0
votes

I'm trying to add a new ssh key. I've started the service using "ssh-agent -s", and I get this response:

SSH_AUTH_SOCK=/tmp/ssh-tUlzwbxYNLaZ/agent.9516; export SSH_AUTH_SOCK;
SSH_AGENT_PID=8992; export SSH_AGENT_PID;
echo Agent pid 8992;

But when I do "ssh-add ~/.ssh/id_rsa" I get the error "Could not open a connection to your authentication agent." Is the start command not working? I'm not sure what the output of the start command means.

1

1 Answers

1
votes

The output that you show above needs to be evaluated. Very often this is done automatically by starting ssh-agent like eval `ssh-agent`. This causes

  • SSH_AUTH_SOCK=/tmp/ssh-tUlzwbxYNLaZ/agent.9516; export SSH_AUTH_SOCK;: the SSH_AUTH_SOCK environment variable to be set to the given value.
  • SSH_AGENT_PID=8992; export SSH_AGENT_PID;: the SSH_AGENT_PID environment variable to be set to the given value.

These two variables need to be set for ssh-add to be able to find the agent. If you want to evaluate them manually you can just copy those commands, paste them into your terminal or console, and hit Enter. Then try using ssh-add again.

The last line, echo Agent pid 8992;, simply prints out the ssh-agent process ID for your information.

These variables cannot be hard-coded because the socket and PID aren't predictable. Each time you start ssh-agent you need to use whatever values it prints out.

Note that these variables only get set for the current shell. So if you do it in a terminal window and then work in that window you should be fine, but if you close the window and open a new terminal it won't work anymore. Similarly if you are logged into a console, then log out and back in again.

Most modern desktop environments start ssh-agent and set the appropriate environment variables for you, so if you're using Gnome or KDE or Unity or something you shouldn't have to do this. If you are manually starting your environment or using something more bare-bones that doesn't handle this for you you should probably add eval `ssh-agent` to your X startup file, e.g. .xinitrc so that it runs before starting X.