304 North Cardinal St.
Dorchester Center, MA 02124
While doing ssh-add in Github or Git you might get “could not open a connection to your authentication agent” error on Windows or Ubuntu / Linux machines. We have a quick fix in this guide.
When you are new to Github and try to add
ssh-keys, you will very often face this problem.
But since this is mandatory, we need to find a way to fix this.
We will use
ssh-agent to fix this with couple of commands.
So let’s first understand why we get an error – could not open a connection to your authentication agent?
Basically what happens is, when you create a new public key and try to add it, there are two points of failure.
As per Github documentation, this is because the
ssh-agent is not running in the background and hence rejects
To fix this run below command :
$ eval "$(ssh-agent -s)" > Agent pid 59566
Then simply re-run the add command :
$ ssh-add ~/.ssh/id_rsa
This should work in most cases. However, if you are using fish shell, you might have to handle it differently.
This is because fish shell has different syntax and does not understand bash format.
The below command should work in the case of fish.
eval "ssh-agent -s"
And then because the export command is not recognized by fish, to add keys we will use
set -x the command
$ set -x SSH_AUTH_SOCK /tmp/ssh-qSWfVCBEZQcc/agent.4858 $ set -x SSH_AGENT_PID 4859
Now run add command.
$ ssh-add ~/.ssh/id_rsa
[su_label type=”success”]Suggested read[/su_label] How to clone a branch in git with just 2 commands
You can also encounter this situation when
SSH_AUTH_SOCK variable is not set and hence the
ssh-add cannot contact an authentication agent.
Verify first that ssh-agent is running on your system by running a command
You should see similar output.
SSH_AUTH_SOCK=/var/folders/65/y74h47ts5sq4f8rdd3z4bny00000gn/T//ssh-NbiggsEgBMbk/agent.33762; export SSH_AUTH_SOCK; SSH_AGENT_PID=33763; export SSH_AGENT_PID; echo Agent pid 33763;
Now just run below command to set ssh-agent to the terminal.
If you do not want to do these manual steps every time you open a new shell window, add
eval $(ssh-agent)command to your shell profile.
[su_label type=”success”]Suggested read[/su_label] How to git remove file from commit after push or staging
In the case of bash, it will be
Let us know if your issue is not solved and still could not open a connection to your authentication agent.