ssh-agent / ssh-add error: could not open a connection to your authentication agent

I type in ssh-agent and get the following back:

SSH_AUTH_SOCK=/tmp/ssh-GqdeT074HLRJ/agent.4670; export SSH_AUTH_SOCK;
SSH_AGENT_ID=4671; export SSH_AGENT_PID;
echo Agent pid 4671;

I then type in ssh-add privkey.pem and get the following:

Could not open a connection to your authentication agent

Any ideas as to what I'm doing wrong? I tried adding sudo before each of those commands, as well, but got near identical output.


Solution 1:

You’re supposed to execute the output that you get back from ssh-agent, like this: eval $(ssh-agent)

Then your environment is set up for ssh-add to connect to the agent.

Solution 2:

You may also use the following syntax:

ssh-agent sh -c 'ssh-add && echo Do some stuff here.'