ssh-add returns with: "Error connecting to agent: No such file or directory"
You need to initialize the agent first.
You can do this in multiple ways. Either by starting a new shell
ssh-agent bash
or by evaluating the variables 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.
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 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>