How to solve “Could not open a connection to your authentication agent”
Problem:
You want to add a ssh key using ssh-add
. It fails with this message:
Could not open a connection to your authentication agent.
Solution
ssh-agent
manages the keys added by ssh-add
. Even if there is already an instance running, the current shell instance may not be aware of it - ssh-agent
sets the environment variable SSH_AGENT_PID
.
In order to start a new instance of ssh-agent, execute this command:
eval $(ssh-agent)
If yo use this approach on a server (which isn’t rebootet regularly), an enormous amount of running ssh agents is accumulated over time. Therefore you might want to execute killall ssh-agent
from time to time to kill all s``sh-agent
instances you can’t use any more (because you can’t access the environment variables any more).