Have a look at the following shell session:

niklas@llw ~ % ssh-agent && ssh-add
SSH_AUTH_SOCK=/tmp/ssh-ZzWYJAmK8809/agent.8809; export SSH_AUTH_SOCK;
echo Agent pid 8810;
Enter passphrase for /home/niklas/.ssh/id_rsa: 
Identity added: /home/niklas/.ssh/id_rsa (/home/niklas/.ssh/id_rsa)

niklas@llw ~ % killall ssh-agent

niklas@llw ~ % ssh-agent && ssh-add
SSH_AUTH_SOCK=/tmp/ssh-TNMkMvgP8880/agent.8880; export SSH_AUTH_SOCK;
echo Agent pid 8881;
Could not open a connection to your authentication agent.

Why can I run ssh-agent && ssh-add only once?


First I suggest you double check and make sure you didn't already have an agent running. I suspect you had an agent already running. Then you started a second, without properly updating the environment. Your ssh-add communicated with the original agent. Then you killed all the agents, and tried starting a new one without properly updating the environment, the following ssh-add couldn't contact the original agent, which you had killed.

Next you need to understand that when the SSH agent starts, it spits out a script that needs to be used to update your environment. This is how client programs know how to contact the agent. One way to do this is with a command like below.

. <(ssh-agent)
  • You are absolutely right. There was already an agent running, which is started before I log in, namely with the use-ssh-agent in /etc/X11/Xsession.options and its implementation in /etc/X11/Xsession.d/90x11-common_ssh-agent. I now simply run ssh-add. – nh2 Feb 25 '13 at 1:25

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.