Windows – ssh-add returns “Error connecting to agent: No such file or directory” even though agent is running

sshssh-agentwindows

Windows 10 20H2, build 19042.685

I'm trying to use the SSH agent in the built-in OpenSSH client on Windows 10. The agent is running:

C:\Users\Daniel> Get-Service | ?{$_.Name -like '*ssh-agent*'}

Status   Name               DisplayName
------   ----               -----------
Running  ssh-agent          OpenSSH Authentication Agent

However, ssh-add is still throwing the same error:

C:\Users\Daniel> ssh-add C:\Users\Daniel\.ssh\id_ed25519
Error connecting to agent: No such file or directory

Any ideas?

Best Answer

I found that something in Windows10 is setting the path to ssh-agent as an env-var, but cannot cope with spaces in foldernames. Someone forgot to escape their inputs! (AAAAAAAARRRRGGGGH!).

To test: (in git-bash, which I'm currently using)

echo "$(ssh-agent)"

...gives what your env has setup (in my case: stupidly) for how it will find/access ssh-agent. I got:

SSH_AUTH_SOCK=/d/Windows10 Temporary Files/ssh-XXXXXXX/agent.YYYYY; export SSH_AUTH_SOCK;
SSH_AGENT_PID=54456; export SSH_AGENT_PID;
echo Agent pid 54456;

...oh look! Someone forgot that folders can have spaces, and didn't bother to escape their inputs (the first line is corrupt, it includes the "export" command).

Re-exporting that env-variable correctly (wrap the "/d/...YYYY" with single quotes, remove the trailing ";", and remove the "export SSH_AUTH_SOCK;" part) causes ssh-agent to work properly again.

Related Topic