4

I need to add multiple ssh keys , so i need to execute ssh-add

But I get error of Could not open a connection to your authentication agent

I read multiply posts like Could not open a connection to your authentication agent and https://superuser.com/questions/901568/ssh-agent-could-not-open-connection

I had started the ssh-agent by

eval ($ssh-agent -s)

and the output is like : Agent pid 13524

but still get this error:

 $ ssh-add ~/.ssh/id_rsa
 Could not open a connection to your authentication agent.

I also set

git config --global url."https://".insteadOf git://

And I echo some variable and get this:

echo $SSH_AGENT_PID
12340 
echo $SSH_AUTH_SOCK 
/tmp/ssh-ZbRZr10908/agent.10908

PS: I am using Windows 7 and the under company's network.

Community
  • 1
  • 1
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149

2 Answers2

9

I tried a lot of solutions online but nothing worked. I made more research and found that the following commands worked.

  1. sudo ssh-agent bash
  2. ssh-add /home/user/.ssh/id_rsa
Umair Afzal
  • 181
  • 1
  • 4
7

You put the start of agent wrong. It should be:

eval $(ssh-agent -s)

But if that will not help, anyway you can troubleshoot the issue by trying to write env variables:

echo $SSH_AGENT_PID
echo $SSH_AUTH_SOCK

and making sure the socket (path from the second echo) exists and have reasonable ACL's. Also checking if the agent itself runs by the PID.

Edit:

I see you are using windows, so there can be problem with the paths. Fortunately ssh-agent supports argument -a with the path to UNIX-domain socket or address to bind. You should try:

 ssh-agent -a ./agent_socket

or

 ssh-agent -a 127.0.0.1:9999

which should work even on windows.

Community
  • 1
  • 1
Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • No use. eval $(ssh-agent -s) -->"Agent pid 12340" echo $SSH_AGENT_PID -->12340 echo $SSH_AUTH_SOCK -->/tmp/ssh-ZbRZr10908/agent.10908 – JaskeyLam Oct 21 '15 at 06:13
  • I see you are using windows. Is it under cygwin or how? If not, it is probable, that the path starting with `/tmp/` will not work for you. – Jakuje Oct 21 '15 at 10:04
  • hmm, I just use gitbash to execute these. – JaskeyLam Oct 21 '15 at 10:42
  • I believe there is problem with the path on windows. You should try to start `ssh-agent` with argument `-a ./agent_socket`. It should create the socket in current directory and then ssh-add should be able to connect to this socket ... hopefully. Otherwise you can try to bind some localhost address, which should work for sure: `ssh-agent -a 127.0.0.1:9999` – Jakuje Oct 21 '15 at 11:02