ssh-add
alone is not working:
Error connecting to agent: No such file or directory
How should I use that tool?
The client tool ssh-add
wants to communicate with the background process ssh-agent
. You need to start the ssh-agent
process first. On Linux, an Shell uses the environment variables SSH_AUTH_SOCK
and SSH_AGENT_PID
to identify the correct process to talk to.
You can start ssh-agent in multiple ways. Either by starting a new shell
ssh-agent bash
or by evaluating the script returned by ssh-agent
in your current shell.
eval "$(ssh-agent)"
I suggest using the second method, because you keep all your history and variables.
fish
, the command is ssh-agent fish
.
Commented
Aug 24, 2018 at 7:43
ssh-agent
, which manages your SSH keys.
In Windows PowerShell (run as admin):
Check the current status of ssh-agent:
Get-Service | ?{$_.Name -like '*ssh-agent*'} | select -Property Name, StartType, Status
Enable the Service if it is disabled:
Set-Service -Name ssh-agent -StartupType Manual
Start the Service:
Start-Service ssh-agent
Add your key as before:
ssh-add <path to the key>
The SSH agent is not running, or the environment variables that it sets are not available in the current environment (most importantly SSH_AUTH_SOCK
), or they are set incorrectly (pointing to a dead agent).
You could start the agent in the current shell session using
eval "$(ssh-agent)"
or start a new shell session through the agent using
ssh-agent fish
(replace fish
with whatever shell you are using). But since you say that you used to be able to use ssh-add
without this, it leads me to believe that you've accidentally killed the agent (or it has terminated due to some other reason). The error message makes me think that the SSH_AUTH_SOCK
environment variable is actually set, but that ssh-add
can't find a valid communication socket at that path.
It would not surprise me if your usual way of doing things would work again if you completely logged out and logged in again, or rebooted the machine.
In my edge case, the problem was I had somehow turned off the service, or it was trying to use bash instead of zsh. Not really sure, but this did the trick:
ssh-agent zsh
What I just stumbled uppon is that I couldn't add the key no matter what I tried. Reinstall openssh, start it in systemd, stop, restart, start ssh-agent, kill all ssh-agent processess running and try with a fresh one... I would always end up with that file or directory not found. In the end I removed all SSH keys that I had in my ~/.ssh, created a fresh one that I custom named, and it still didn't work. What did work is when I renamed that key to id_rsa
. For some reason the agent picked that up automatically without the need to add the key to it and started working. Happened on Arch.
ssh-add
command can't communicate with the SSH agent. In your case, the ssh-add
command could not read your key (possibly due to a permission or ownership issue; you may have used sudo
to generate the key or to create the ~/.ssh
directory).
$SSH_AUTH_SOCK
environment variable points to. If the variable is unset (if you never started the agent), ssh-add
says Could not open a connection to your authentication agent
.
ssh-add
with no options). There is also no reference to thetmux
tag in the question itself. For more feedback, ask about your question on the Meta site.