Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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;
SSH_AGENT_PID=8810; export SSH_AGENT_PID;
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;
SSH_AGENT_PID=8881; export SSH_AGENT_PID;
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
add comment

1 Answer

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)
ssh-add
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
add comment

Your Answer

 
discard

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.