ssh-add complains: Could not open a connection to your authentication agent

395,560

Solution 1

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.

Solution 2

Try this one:

$ ssh-agent /bin/sh
$ ssh-add $yourkey

Solution 3

This question has been also very well covered on Stackoverflow.

eval `ssh-agent -s`

ssh-add

Solution 4

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

Solution 5

You may also use the following syntax:

ssh-agent sh -c 'ssh-add && echo Do some stuff here.'
Share:
395,560

Related videos on Youtube

geek_guy
Author by

geek_guy

Updated on September 18, 2022

Comments

  • geek_guy
    geek_guy over 1 year

    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;
    SSH_AGENT_PID=2807; export SSH_AGENT_PID;
    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?

    • sunnysideup
      sunnysideup over 11 years
      Try eval $(ssh-agent)
  • geek_guy
    geek_guy over 11 years
    Thanks, I didn't quite understand how it works. Thats very muchly appreciated.
  • RaduM
    RaduM almost 11 years
    Or you can enter ssh-agent bash and after the ssh-add will work
  • Denys S.
    Denys S. over 10 years
    @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?
  • Stéphane Chazelas
    Stéphane Chazelas over 10 years
    @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).
  • Denys S.
    Denys S. over 10 years
    @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?
  • Joseph Snow
    Joseph Snow over 9 years
    This actually worked for me where none of the other answers worked.
  • Ain Tohvri
    Ain Tohvri almost 9 years
    This isn't working for me, if you go ssh-agent sh -c "ssh-add -l" it will tell you you have no identities.
  • kenorb
    kenorb almost 9 years
    Because you've to add it first, for example: ssh-agent sh -c "ssh-add && ssh-add -l" will print your identity.
  • Stéphane Chazelas
    Stéphane Chazelas over 8 years
    @KamijouTouma, I've reverted the edit. Please add that information in your own answer as I don't agree with all you've said in that edit.
  • Stéphane Chazelas
    Stéphane Chazelas over 8 years
    Note that you can also give root access to your ssh-agent by doing sudo SSH_AUTH_SOCK="$SSH_AUTH_SOCK" npm install...
  • Belldandu
    Belldandu over 8 years
    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.
  • Stéphane Chazelas
    Stéphane Chazelas over 8 years
    You forgot the quotes around `...`. Without them, the split+glob operator is invoked on the output.
  • Belldandu
    Belldandu over 8 years
    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
    Belldandu over 8 years
    @StéphaneChazelas is this acceptable?
  • slackmart
    slackmart about 8 years
    If you are using the fishshell, this answer works. ssh-agent /usr/bin/fish.
  • IgorGanapolsky
    IgorGanapolsky over 7 years
    I get an error: "Could not open a connection to your authentication agent."
  • IgorGanapolsky
    IgorGanapolsky over 7 years
    I get an error: "Could not open a connection to your authentication agent."
  • IgorGanapolsky
    IgorGanapolsky over 7 years
    "bash: start-ssh-agent: command not found"
  • IgorGanapolsky
    IgorGanapolsky over 7 years
    I still get an error: key_load_private_type: Permission denied
  • cjm
    cjm over 7 years
    @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.
  • Danny Schoemann
    Danny Schoemann over 7 years
    This worked on an ancient Fedora release 10 (Cambridge) box. Thanks.
  • Liam Dawson
    Liam Dawson over 5 years
    -1: using sudo is not relevant to the question and is dangerous advice for common usage.
  • BertC
    BertC about 3 years
    This worked for me also, but can anybody explain what the "ssh-agent /bin/sh" does?
  • Fl_ori4n
    Fl_ori4n almost 3 years
    RUN ssh-agent sh -c 'ssh-add /root/.ssh/id_rsa' worked for me in a dockerfile