[Fixed] SSH : could not open a connection to your authentication agent

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.

1. SSH agent not running

As per Github documentation, this is because the ssh-agent is not running in the background and hence rejects ssh-add command.

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
Suggested read How to clone a branch in git with just 2 commands
Also check :   GitHub Profile Readme 101: Awesome Samples & how to create one?

2. SSH_AUTH_SOCK not set

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

$ ssh-agent

You should see similar output.

SSH_AUTH_SOCK=/var/folders/65/y74h47ts5sq4f8rdd3z4bny00000gn/T//ssh-NbiggsEgBMbk/agent.33762; export SSH_AUTH_SOCK;
echo Agent pid 33763;

Now just run below command to set ssh-agent to the terminal.

eval $(ssh-agent)

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.

Suggested read How to git remove file from commit after push or staging

In the case of bash, it will be ~/.bash_profile.

Let us know if your issue is not solved and still could not open a connection to your authentication agent.

Get occasional tutorials & guides in your inbox. No spam ever.

Buy Me A Coffee

Leave a Comment