ssh-add complains: Could not open a connection to your authentication agent
I’ve been trying to get ssh-add
working on a RaspberryPi running Raspbian.
I can start ssh-agent
, when I do it gives the following output into the terminal:
SSH_AUTH_SOCK=/tmp/ssh-06TcpPflMg58/agent.2806; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2807; export SSH_AGENT_PID;
echo Agent pid 2807;
If I run ps aux | grep ssh
I can see it is running.
Then I try to run ssh-add
in order to add my key passphrase, and I get the following:
Could not open a connection to your authentication agent.
Any ideas?
Your shell is meant to evaluate that shell code output by ssh-agent
. Run this instead:
eval "$(ssh-agent)"
Or if you’ve started ssh-agent already, copy paste it to your shell prompt (assuming you’re running a Bourne-like shell).
ssh
commands need to know how to talk to the ssh-agent
, they know that from the SSH_AUTH_SOCK
environment variable.
Try this one:
$ ssh-agent /bin/sh
$ ssh-add $yourkey
If using csh as a shell (FreeBSD PI) this could work:
eval `ssh-agent -c`
next you only need to do something like:
ssh-add ~/.ssh/id_rsa
This question has been also very well covered on Stackoverflow.
eval `ssh-agent -s`
ssh-add
You may also use the following syntax:
ssh-agent sh -c 'ssh-add && echo Do some stuff here.'
Try this:
go to C:$Installation_Folder$Gitcmd
and execute:
start-ssh-agent
It will open a cmd command and run the ssh-agent
the right way.
ssh-add ~/.ssh/id_rsa
should then work.
This was confusing, and has 2 possible good answers, depending on whether the user is attempting to add a ssh key on a Linux or on Windows (as I am). This probably doesn’t answer the OP, but is an expansion for git-bash. I run both Windows and Ubuntu for development, and my git installation is slightly different in each.
Try this: go to C:$Installation_Folder$Gitcmd and execute:
start-ssh-agent It will open a cmd command and run the ssh-agent the
right way.
.. was a good Windows answer, but failed to specify that you were expected to go through Windows Explorer to find the Git installation folder, and run the the Windows shell would open on completion of step 1.
“go to C:$Installation_Folder$Gitcmd”
Step 2: you just need to double-click
start-ssh-agent
On step 3, you go back to git-bash or whichever *nix terminal emulator you are running and run ssh-add. If you used the default name for the ssh public key, you don’t have to add the name as ssh-add uses that automatically.
There’s a couple of ways if you wish to use an identity with sudo,
e.g. sudo npm install
.
Long way, but also gives you root access so you won’t need to use sudo
a lot.
- Run
sudo ssh-agent bash
This will ask for your password and after will runssh-agent
with the superuser’s privileges, - Navigate to your users’ .ssh folder
cd /home/user/.ssh
-
From there you can run
ssh-add id_rsa npm install git+ssh://git@YOUR-PROJECT-URL -g && npm link PROJECT-NAME
Short way, only your user (unless you want to sudo a lot)
eval "$(ssh-agent)"
ssh-add
sudo SSH_AUTH_SOCK="$SSH_AUTH_SOCK" npm install git+ssh://git@PROJECT-URL -g && sudo npm link PROJECT-NAME
The easiest solution does not have to be bad.
You need neither ssh-agent
nor ssh-add
when you use a passwordless private key, see https://stackoverflow.com/a/48290333/11154841.
By this, I got rid of the error Could not open a connection to your authentication agent. ssh-add exit code 2
.
That does not need to be insecure: you simply need to delete both keys of the key pair right after their usage. That means, you must delete the public key on the server and delete the private key on the client. It goes without saying: never use them again, do not even keep a backup somewhere.
Mind that you can create the public key from a private key, but not the other way round. Normally, it should suffice to simply delete the public key from the registered keys on your Git portal, but they should better be both deleted, so that the same public key can never ever be used again. Even if someone had stolen your private key, it would be of no use if you simply never use its public key again.
With a passwordless private key, you can even use it in Docker to get around any password entries. You can clone a git repo without any password, the passwordless private key is all you need. See Dockerfile: clone repo with passwordless private key. Errors: “authentication agent” or “read_passphrase: can’t open /dev/tty” as an example.