Error connecting to agent: No such file or directory (SSH) — how to fix
Error connecting to agent: No such file or directory
Quick fix: Windows (admin PowerShell): Get-Service ssh-agent | Set-Service -StartupType Automatic; Start-Service ssh-agent, then ssh-add. Linux/macOS: start an agent in the current shell with eval "$(ssh-agent -s)", then ssh-add ~/.ssh/id_ed25519.
What it means
ssh-add talks to ssh-agent over a local socket (Linux/macOS) or a named pipe (Windows, \\.\pipe\openssh-ssh-agent). "No such file or directory" means that socket or pipe doesn't exist: no agent is listening where the client is looking. A variant, Error connecting to agent: Connection refused, means the socket file exists but the agent behind it is gone.
The older message for the same problem is "Could not open a connection to your authentication agent", covered on its own page.
Fix 1: Windows, start the OpenSSH Authentication Agent service
This is the most common case. Windows ships the agent as a service that is disabled by default. In PowerShell as Administrator:
Get-Service ssh-agent
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
Then, in a normal PowerShell:
ssh-add $env:USERPROFILE\.ssh\id_ed25519
ssh-add -l
If Get-Service ssh-agent finds nothing, the OpenSSH Client optional feature isn't installed: Settings > System > Optional features > OpenSSH Client.
Fix 2: Git for Windows using the wrong ssh
Git Bash ships its own OpenSSH, which uses a Unix-style socket, not the Windows service. If you started the Windows service but use Git Bash, either start an agent inside Git Bash:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
or make Git use the Windows OpenSSH (and its agent):
git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
Fix 3: Linux/macOS, no agent in this shell
ssh-agent prints environment variables but can't set them in your shell by itself. Run it through eval:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Check what the client is looking at:
echo "$SSH_AUTH_SOCK"
ls -l "$SSH_AUTH_SOCK"
Empty output or "No such file" confirms there's no agent here. Desktop sessions (GNOME, macOS) normally start one at login; plain SSH sessions, sudo -i, containers, cron and tmux sessions started earlier often don't have it.
Fix 4: stale SSH_AUTH_SOCK in tmux or screen
A tmux session keeps the SSH_AUTH_SOCK value from when it was created. After you reconnect, the old socket is gone. Update the variable in the pane:
eval "$(tmux show-environment -s SSH_AUTH_SOCK)"
Or point a stable symlink at the current socket from ~/.ssh/rc on the server and use that path in tmux.
Fix 5: agent forwarding not active
If you expect a forwarded agent on a remote host, SSH_AUTH_SOCK there is only set when you connect with ssh -A (or ForwardAgent yes for that host) and the server allows AllowAgentForwarding. Reconnect with forwarding, and avoid sudo dropping the variable (sudo -E or SSH_AUTH_SOCK in env_keep).
Start the agent automatically
On Linux, add to ~/.ssh/config so keys are loaded into the agent on first use:
Host *
AddKeysToAgent yes
On macOS, also add UseKeychain yes to store the passphrase in the keychain.
Last updated 2026-12-03.