ssh-add complains: Could not open a connection to your authentication agent
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.'
Related videos on Youtube
geek_guy
Updated on September 18, 2022Comments
-
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 over 11 yearsTry
eval $(ssh-agent)
-
-
geek_guy over 11 yearsThanks, I didn't quite understand how it works. Thats very muchly appreciated.
-
RaduM almost 11 yearsOr you can enter ssh-agent bash and after the ssh-add will work
-
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 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. 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 over 9 yearsThis actually worked for me where none of the other answers worked.
-
Ain Tohvri almost 9 yearsThis isn't working for me, if you go
ssh-agent sh -c "ssh-add -l"
it will tell you you have no identities. -
kenorb almost 9 yearsBecause you've to add it first, for example:
ssh-agent sh -c "ssh-add && ssh-add -l"
will print your identity. -
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 over 8 yearsNote that you can also give
root
access to your ssh-agent by doingsudo SSH_AUTH_SOCK="$SSH_AUTH_SOCK" npm install...
-
Belldandu over 8 yearsTried 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 over 8 yearsYou forgot the quotes around
`...`
. Without them, the split+glob operator is invoked on the output. -
Belldandu over 8 yearsi 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 over 8 years@StéphaneChazelas is this acceptable?
-
slackmart about 8 yearsIf you are using the fishshell, this answer works.
ssh-agent /usr/bin/fish
. -
IgorGanapolsky over 7 yearsI get an error: "Could not open a connection to your authentication agent."
-
IgorGanapolsky over 7 yearsI get an error: "Could not open a connection to your authentication agent."
-
IgorGanapolsky over 7 years"bash: start-ssh-agent: command not found"
-
IgorGanapolsky over 7 yearsI still get an error: key_load_private_type: Permission denied
-
cjm over 7 years@slackmart If you installed fish in BSD, its location is
/usr/local/bin/fish
(alternatively/usr/ports/shells/fish
). Thank thewhereis
command for helping me figure that out. -
Danny Schoemann over 7 yearsThis worked on an ancient Fedora release 10 (Cambridge) box. Thanks.
-
Liam Dawson over 5 years-1: using
sudo
is not relevant to the question and is dangerous advice for common usage. -
BertC about 3 yearsThis worked for me also, but can anybody explain what the "ssh-agent /bin/sh" does?
-
Fl_ori4n almost 3 years
RUN ssh-agent sh -c 'ssh-add /root/.ssh/id_rsa'
worked for me in a dockerfile