Skip to content

Instantly share code, notes, and snippets.

@mvneves
Last active March 9, 2025 12:32
Show Gist options
  • Save mvneves/a6a69a53f039b3755900 to your computer and use it in GitHub Desktop.
Save mvneves/a6a69a53f039b3755900 to your computer and use it in GitHub Desktop.
"Could not open a connection to your authentication agent"

SSH authentication agent does not automatically start when using it from a remote server. This results in the following error message:

$ git pull
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
$ ssh-add ~/my-ssh-key.pem
Could not open a connection to your authentication agent.

To fix it requires manually starting ssh-agent:

$ eval `ssh-agent -s`
Agent pid 13442
$ ssh-add ~/my-ssh-key.pem
Identity added: /home/user/my-ssh-key.pem (/home/user/my-ssh-key.pem)
$ git pull
@erias58
Copy link

erias58 commented May 4, 2024

SSH_AUTH_SOCK=/tmp/ssh-WvEP0dKfXLyl/agent.1753; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1754; export SSH_AGENT_PID;
echo Agent pid 1754;

if i try adding the key again
it returns "could not open connection to your authentication agent.

@mikerdiaz
Copy link

mikerdiaz commented Mar 9, 2025

Perfect for me, thank you!

miked@MRDM MINGW64 ~ (main)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-2S5lHW5cWifQ/agent.1452; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1453; export SSH_AGENT_PID;
echo Agent pid 1453;

miked@MRDM MINGW64 ~ (main)
$ ssh-add c:/Users/miked/.ssh/id_ed25519
Could not open a connection to your authentication agent.

miked@MRDM MINGW64 ~ (main)
$ eval ssh-agent -s
Agent pid 1468

miked@MRDM MINGW64 ~ (main)
$ ssh-add c:/Users/miked/.ssh/id_ed25519
Identity added: c:/Users/miked/.ssh/id_ed25519

miked@MRDM MINGW64 ~ (main)

@robisonweb
Copy link

robisonweb commented Mar 9, 2025

Thank you very much for your contribution @mvneves

I use access via VS Code, does anyone have a solution so that when I load VS Code it ​​already runs these commands?

I tried .bash_profile and other approaches but without success.

Do you have any examples?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment