18

I type in ssh-agent and get the following back:

SSH_AUTH_SOCK=/tmp/ssh-GqdeT074HLRJ/agent.4670; export SSH_AUTH_SOCK;
SSH_AGENT_ID=4671; export SSH_AGENT_PID;
echo Agent pid 4671;

I then type in ssh-add privkey.pem and get the following:

Could not open a connection to your authentication agent

Any ideas as to what I'm doing wrong? I tried adding sudo before each of those commands, as well, but got near identical output.

26

You’re supposed to execute the output that you get back from ssh-agent, like this: eval $(ssh-agent)

Then your environment is set up for ssh-add to connect to the agent.

  • I tried sudo eval $(ssh-agent) and it said sudo: eval: command not found. I tried eval $(sudo ssh-agent) and it said Agent pid 4735 and then, after both of those, ssh-add still doesn't work. Any ideas? – neubert Jan 28 '14 at 5:27
  • 1
    never mind - doing sudo bash and then doing all that got the job done. thanks! – neubert Jan 28 '14 at 5:42
  • "eval ssh-agent" also works. I didn't need any sudo. – labyrinth Mar 12 '14 at 17:08
  • doing eval and then ssh-add still did not work for me, any ideas why? – user3226932 Apr 28 '17 at 8:26
3

You may also use the following syntax:

ssh-agent sh -c 'ssh-add && echo Do some stuff here.'
-1

I found solution:

run below command OR add to .bashrc file

exec ssh-agent bash

ssh-add [key path]

  • 1
    (1) Two solutions have already been posted, and one has been accepted as correct.  Does yours have any advantage over those earlier ones?  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Do you really believe that it’s a good idea to exec bash from within .bashrc?  Have you tried it?  Before you do, think hard about what will happen.  (Hint: what does a new bash process do when it starts?)  If you do dare to try it, you might want to make sure that you have another shell window open. – Scott Feb 15 '17 at 8:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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