Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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)
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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