How to fix "Could not open a connection to your authentication agent." error when trying to add ssh-key?

Solution 1:

You need to run ssh-agent first. You'll receive output like this:

SSH_AUTH_SOCK=/tmp/ssh-mZueDP7822/agent.7822; export SSH_AUTH_SOCK;
SSH_AGENT_PID=7823; export SSH_AGENT_PID;
echo Agent pid 7823;

Now just paste that into your terminal and add your keys.

Solution 2:

Of course atx answer is right but instead of copying you can run ssh-agent with eval.

eval `ssh-agent -s`