Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

I've been trying to get ssh-add working on a RaspberryPi running Raspbian.

I can start ssh-agent, when I do it gives the following output into the terminal:

SSH_AUTH_SOCK=/tmp/ssh-06TcpPflMg58/agent.2806; export SSH_AUTH_SOCK;
echo Agent pid 2807;

If I run ps aux | grep ssh I can see it is running.

Then I try to run ssh-add in order to add my key passphrase, and I get the following:

Could not open a connection to your authentication agent.

Any ideas?

share|improve this question
Try eval $(ssh-agent) – Ulrich Dangel Sep 22 '12 at 15:28
up vote 106 down vote accepted

Your shell is meant to evaluate that shell code output by ssh-agent. Run this instead:

eval "$(ssh-agent)"

Or if you've started ssh-agent already, copy paste it to your shell prompt (assuming you're running a Bourne-like shell).

ssh commands need to know how to talk to the ssh-agent, they know that from the SSH_AUTH_SOCK environment variable.

share|improve this answer
Thanks, I didn't quite understand how it works. Thats very muchly appreciated. – Daniel Groves Sep 22 '12 at 17:30
Or you can enter ssh-agent bash and after the ssh-add will work – RaduM May 15 '13 at 13:56
@Stephane, do I get it correctly that ssh-agent command just prints the output of it's execution while eval version actually runs the command? – Denys S. Oct 7 '13 at 8:50
@DenysS. Well no, it does its setup and then tells your shell how to update its environment to be able to contact it. It cannot do that by itself. It can start a new shell with the updated environment (that's what ssh-agent bash does), but it cannot update the memory of a separate process running a foreign command (your already running shell). – Stéphane Chazelas Oct 7 '13 at 9:03
@StephaneChazelas, if my ssh-agent is started on boot but I still have to eval it in my shell does it mean that it is not automatically evaluated for every shell and has to be configured somehow by the root user? – Denys S. Oct 7 '13 at 9:10

Try this one:

$ ssh-agent /bin/sh
$ ssh-add $yourkey
share|improve this answer
This actually worked for me where none of the other answers worked. – Joseph Snow Nov 12 '14 at 18:06
If you are using the fishshell, this answer works. ssh-agent /usr/bin/fish. – slackmart Mar 29 at 18:17

This question has been also very well covered on Stackoverflow.

eval `ssh-agent -s`

share|improve this answer
You forgot the quotes around `...`. Without them, the split+glob operator is invoked on the output. – Stéphane Chazelas Dec 9 '15 at 9:56

If using csh as a shell (FreeBSD PI) this could work:

eval `ssh-agent -c`

next you only need to do something like:

ssh-add ~/.ssh/id_rsa
share|improve this answer

You may also use the following syntax:

ssh-agent sh -c 'ssh-add && echo Do some stuff here.'
share|improve this answer
This isn't working for me, if you go ssh-agent sh -c "ssh-add -l" it will tell you you have no identities. – Ain Tohvri Jul 1 '15 at 13:43
Because you've to add it first, for example: ssh-agent sh -c "ssh-add && ssh-add -l" will print your identity. – kenorb Jul 3 '15 at 17:25

This was confusing, and has 2 possible good answers, depending on whether the user is attempting to add a ssh key on a Linux or on Windows (as I am). This probably doesn't answer the OP, but is an expansion for git-bash. I run both Windows and Ubuntu for development, and my git installation is slightly different in each.

Try this: go to C:\$Installation_Folder$\Git\cmd and execute:

start-ssh-agent It will open a cmd command and run the ssh-agent the right way.

.. was a good Windows answer, but failed to specify that you were expected to go through Windows Explorer to find the Git installation folder, and run the the Windows shell would open on completion of step 1.
"go to C:\$Installation_Folder$\Git\cmd"

Step 2: you just need to double-click


On step 3, you go back to git-bash or whichever *nix terminal emulator you are running and run ssh-add. If you used the default name for the ssh public key, you don't have to add the name as ssh-add uses that automatically.

share|improve this answer

Try this: go to C:\$Installation_Folder$\Git\cmd and execute:


It will open a cmd command and run the ssh-agent the right way.

ssh-add ~/.ssh/id_rsa should then work.

share|improve this answer

If you wish to use an identity with sudo e.g. sudo npm install

Long Way

But also gives you root access so you wont need to type sudo a bunch

Then run the following

sudo ssh-agent bash

This will ask for your password and after will make you root from there you should navigate to whichever users .ssh folder you wish to be so

cd /home/user/.ssh

and from there you can just ssh-add id_rsa npm install git+ssh://git@yourprojecturlhere -g && npm link yourprojectnamehere

Short Way

Only your user (unless you wanna sudo a bunch to get another users use the long way)

eval "$(ssh-agent)" ssh-add sudo SSH_AUTH_SOCK="$SSH_AUTH_SOCK" npm install git+ssh://git@yourprojecturlhere -g && sudo npm link yourprojectnamehere

share|improve this answer
export and eval work just as well as root provided root's login shell is Bourne like. If root's shell is csh or tcsh, use eval `ssh-agent -c` – Stéphane Chazelas Dec 8 '15 at 22:50
Note that you can also give root access to your ssh-agent by doing sudo SSH_AUTH_SOCK="$SSH_AUTH_SOCK" npm install... – Stéphane Chazelas Dec 8 '15 at 22:51
Tried both also bash is bourne again shell and neither worked properly. all users on my debian jessie instance including root are set to use bash by default. – Kamijou Touma Dec 8 '15 at 23:51
What did you try? eval "$(ssh-agent)" at the prompt of a bash shell running as root will work. You'll obviously need to run ssh from that shell or its descendant so they inherit the SSH_AUTH_SOCK env var. eval "$(sudo ssh-agent)"; sudo ssh... won't work because sudo by default doesn't pass the SSH_AUTH_SOCK env var. – Stéphane Chazelas Dec 9 '15 at 9:50
i tried eval "$(ssh-agent)" ill be looking later to see if there is some sort of configuration error. Although the current way i have given this guide allows free control over which user you wish to be since your already root and can access any users id_rsa thats on the server. So once i get it working appropriately ill edit my answer. – Kamijou Touma Dec 9 '15 at 19:51

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.