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?


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.

  • Thanks, I didn't quite understand how it works. Thats very muchly appreciated. – Daniel Groves Sep 22 '12 at 17:30
  • 4
    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
  • 5
    @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
  • 5
    This actually worked for me where none of the other answers worked. – Joseph Snow Nov 12 '14 at 18:06
  • 3
    If you are using the fishshell, this answer works. ssh-agent /usr/bin/fish. – slackmart Mar 29 '16 at 18:17
  • 2
    I get an error: "Could not open a connection to your authentication agent." – IgorGanapolsky Aug 12 '16 at 17:29
  • @slackmart If you installed fish in BSD, its location is /usr/local/bin/fish (alternatively /usr/ports/shells/fish). Thank the whereis command for helping me figure that out. – cjm Aug 26 '16 at 4:28
  • Great @cjm, I use Slackware Linux, and that's the path that works for me. – slackmart Aug 27 '16 at 11:35

This question has been also very well covered on Stackoverflow.

eval `ssh-agent -s`

  • 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
  • 1
    I get an error: "Could not open a connection to your authentication agent." – IgorGanapolsky Aug 12 '16 at 18:41

You may also use the following syntax:

ssh-agent sh -c 'ssh-add && echo Do some stuff here.'
  • 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

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.

  • "bash: start-ssh-agent: command not found" – IgorGanapolsky Aug 12 '16 at 18:42

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.


There’s a couple of ways if you wish to use an identity with sudo, e.g. sudo npm install.

Long way, but also gives you root access so you won’t need to use sudo a lot.

  1. Run
    sudo ssh-agent bash
    This will ask for your password and after will run ssh-agent with the superuser’s privileges,
  2. Navigate to your users’ .ssh folder
    cd /home/user/.ssh
  3. From there you can run

    ssh-add id_rsa
    npm install git+ssh://git@YOUR-PROJECT-URL -g && npm link PROJECT-NAME

Short way, only your user (unless you want to sudo a lot)

eval "$(ssh-agent)"
sudo SSH_AUTH_SOCK="$SSH_AUTH_SOCK" npm install git+ssh://git@PROJECT-URL -g && sudo npm link PROJECT-NAME
  • 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. – Belldandu 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. – Belldandu Dec 9 '15 at 19:51

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.