ssh-add alone is not working:

Error connecting to agent: No such file or directory

How should I use that tool?

  • 1
    Dear moderators, I was ask to moved this question to this site from StackOverflow, but then I got downvote again? Can you at least tell me why? – Wong Jia Hau Aug 24 '18 at 7:45
  • I'm not a moderator, but simply googling the error message would have given you an answer. stackoverflow.com/questions/17846529/… – Panki Aug 24 '18 at 7:56
  • 1
    @Panki I tried that solution, it doesn't work, so I came to ask a new question. – Wong Jia Hau Aug 24 '18 at 8:01
  • 1
    Please read our FAQ, take the tour and lurk for a while to get a feel of the forum use. – Rui F Ribeiro Aug 24 '18 at 8:07
  • 1
    Thank you for all the moderators who helped me to improve this questions! – Wong Jia Hau Aug 24 '18 at 12:27

You need to initialize the agent first.

ssh-agent bash
  • 2
    Thanks it works for me! Since I'm using fish, the command is ssh-agent fish. – Wong Jia Hau Aug 24 '18 at 7:43
  • that didn't work for me – Necktwi May 15 at 4:44

The SSH agent is not running, or the environment variables that it sets are not available in the current environment (most importantly SSH_AUTH_SOCK), or they are set incorrectly (pointing to a dead agent).

You could start the agent in the current shell session using

eval "$(ssh-agent)"

or start a new shell session through the agent using

ssh-agent fish

(replace fish with whatever shell you are using). But since you say that you used to be able to use ssh-add without this, it leads me to believe that you've accidentally killed the agent (or it has terminated due to some other reason). The error message makes me think that the SSH_AUTH_SOCK environment variable is actually set, but that ssh-add can't find a valid communication socket at that path.

It would not surprise me if your usual way of doing things would work again if you completely logged out and logged in again, or rebooted the machine.

  • Yes, I think I killed the agent accidentally, perhaps due to restarting the machine. – Wong Jia Hau Aug 24 '18 at 8:26
  • Thanks! Fixed my issue with “Permission denied” – Lorin Rivers Mar 1 at 22:47

In windows power shell:

  1. Check the current status of ssh-agent: "Get-Service | select -property name,starttype"
  2. Set the new type : "Set-Service -Name ssh-agent -StartupType Manual"
  3. Start it: "Start-Service ssh-agent"
  4. Add your key as before: "ssh-add"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.