How to fix Could not open a connection to your authentication agent. in SSH

SSHBEGINNERLOWUpdated May 28, 2026ยท 428 views

"Could not open a connection to your authentication agent" means the SSH agent isn't running or SSH_AUTH_SOCK isn't set. Start the agent with eval and add your key.

Quick fix

Fixes Could not open a connection to your authentication agent.

eval $(ssh-agent -s)
  1. Start the SSH agent with eval
  2. Verify the SSH agent is running
  3. Add your SSH key to the agent
  4. Make the SSH agent persistent across sessions (Linux/macOS)
ssh โ€” error
eval $(ssh-agent -s)
Could not open a connection to your authentication agent.

What this error means

SSH uses an agent process to securely hold your private keys in memory and provide them to SSH clients when needed for authentication. When you run ssh-add or try to authenticate via SSH (for example with Git), the SSH client looks for the agent via the SSH_AUTH_SOCK environment variable. If the agent isn't running or that variable isn't set, you get this error. This is a configuration issue, not a key or permissions problem.

Typical symptoms

  • ssh-add command fails with the authentication agent error
  • Git push/pull fails when using SSH keys
  • SSH key authentication fails even though the key exists
  • Error appears on first terminal session after reboot
  • Error occurs when SSH environment variables are unset
  • Works fine from one shell but fails from another (different environment)

Common causes

  1. SSH agent is not running in your current shell session
  2. SSH_AUTH_SOCK environment variable is not set or points to an invalid socket
  3. SSH agent was not started with eval (missing eval $(ssh-agent -s))
  4. SSH agent process was restarted or the system was rebooted, clearing the agent
  5. SSH environment variables were not exported to the current shell or subshells
  6. Desktop environment or application launcher doesn't pass the SSH agent socket to child processes
  7. Using SSH in a new terminal window that hasn't initialized the agent
  8. SSH_AUTH_SOCK points to a stale socket file that no longer exists

How to fix "Could not open a connection to your authentication agent."

1Start the SSH agent with eval

The SSH agent must be started and its environment variables exported to your shell. Use the eval command to do this correctly:

bash
eval $(ssh-agent -s)

Or if you're using a C-shell compatible shell (csh/tcsh):

bash
eval `ssh-agent -c`

Or if you're using fish shell:

bash
ssh-agent /usr/bin/fish

The eval command is critical: it ensures the SSH_AUTH_SOCK and SSH_AGENT_PID environment variables are exported to your current shell. Simply running ssh-agent alone won't set up these variables for your session.

2Verify the SSH agent is running

After starting the agent, verify the environment variables are set:

bash
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID

Both should print non-empty values. If they're empty, ssh-agent didn't start correctly. Try the previous step again or check for errors in the output.

You can also list running SSH agents:

bash
ps aux | grep ssh-agent

You should see a process such as: /usr/bin/ssh-agent

3Add your SSH key to the agent

Once the agent is running, add your private key to it. For the default key location:

bash
ssh-add ~/.ssh/id_ed25519

If your key has a different name or location (for example ~/.ssh/id_rsa), replace the path accordingly.

You may be prompted for the key's passphrase (if it has one). After entering it, the key is loaded into the agent and won't require the passphrase again during this session.

Verify the key was added:

bash
ssh-add -l

This lists all keys currently loaded in the agent.

4Make the SSH agent persistent across sessions (Linux/macOS)

To avoid manually starting the agent each time you open a terminal, add initialization code to your shell configuration file.

For bash, add this to ~/.bashrc:

bash
if [ -z "$SSH_AUTH_SOCK" ]; then
  eval $(ssh-agent -s)
  ssh-add ~/.ssh/id_ed25519 2>/dev/null
fi

For zsh, add this to ~/.zshrc:

bash
if [ -z "$SSH_AUTH_SOCK" ]; then
  eval $(ssh-agent -s)
  ssh-add ~/.ssh/id_ed25519 2>/dev/null
fi

For fish, add this to ~/.config/fish/config.fish:

fish
if not set -q SSH_AUTH_SOCK
  eval (ssh-agent -c)
  ssh-add ~/.ssh/id_ed25519 2>/dev/null
end

The if check prevents starting multiple agents if you open multiple terminals. After editing your shell config, reload it:

bash
source ~/.bashrc  # or ~/.zshrc, ~/.config/fish/config.fish

On macOS, prefer the system-managed agent and load keys into the Keychain instead of starting your own agent in shell config:

bash
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
5Fix the SSH agent for systemd/desktop environments (Linux)

If you're using systemd on Linux (most modern distributions), enable the SSH agent socket:

bash
systemctl --user enable --now ssh-agent.socket

If this succeeds, you should no longer need to manually start ssh-agent.

For GNOME desktop users on recent systems with GNOME Keyring v46+, the SSH agent functionality may be in a separate package. Check if gcr-ssh-agent is active:

bash
systemctl --user status gcr-ssh-agent.socket

If it's not active, enable it:

bash
systemctl --user enable --now gcr-ssh-agent.socket

Then set the SSH_AUTH_SOCK environment variable in your shell config:

bash
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gcr/ssh
6Fix the SSH agent on Windows with OpenSSH

Windows users with OpenSSH installed may need to enable the SSH Agent service.

1. Open Services (press Win + R, type services.msc, and press Enter)
2. Look for "OpenSSH Authentication Agent"
3. If it's stopped, right-click and select "Start"
4. Set the startup type to "Automatic" (or "Manual" if you prefer to start it on demand)

Alternatively, start it from PowerShell as administrator:

powershell
Start-Service ssh-agent

To have it start at boot:

powershell
Set-Service ssh-agent -StartupType Automatic

If the service doesn't exist, ensure OpenSSH for Windows is properly installed.

7Check for stale SSH_AUTH_SOCK files

Sometimes the SSH_AUTH_SOCK environment variable points to a socket file that no longer exists (stale socket).

Check whether the socket file exists:

bash
ls -la $SSH_AUTH_SOCK

If you get "No such file or directory," the socket is stale. Unset the variables and restart the agent:

bash
unset SSH_AUTH_SOCK
unset SSH_AGENT_PID
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519

This clears any stale references and starts a fresh agent.

Advanced notes

Advanced troubleshooting:

Multiple SSH Keys: If you have multiple SSH keys (for example personal and work), add them all to the agent:

bash
ssh-add ~/.ssh/id_ed25519
ssh-add ~/.ssh/id_work
ssh-add -l  # List all loaded keys

Different hosts can then use different keys automatically based on your SSH config entries.

SSH Config File: Use ~/.ssh/config to specify which key to use for which host. Adding IdentitiesOnly yes prevents the agent from offering every loaded key (which can trip MaxAuthTries on the server):

bash
Host github.com
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes
  User git

Host work-server
  IdentityFile ~/.ssh/id_work
  IdentitiesOnly yes
  User username

Reaching servers behind a bastion (prefer ProxyJump over agent forwarding): If you need to reach an internal host through a jump/bastion host, use ProxyJump (-J). It does not expose your agent to the intermediate host, because authentication to each hop happens from your local machine over a tunneled connection:

bash
ssh -J user@bastion user@internal-host

Or in ~/.ssh/config:

bash
Host internal-host
  ProxyJump user@bastion
  User user

SSH Agent Forwarding (convenient but risky): Agent forwarding (ssh -A) lets a remote host use your local agent's keys without copying the keys to that host:

bash
ssh -A user@remote-host

However, forwarding is a real security risk and should not be treated as "more secure." While you are connected, anyone with root on the remote host (or any process that can read the forwarded socket at $SSH_AUTH_SOCK there) can hijack your agent and authenticate to other systems as you for the lifetime of the connection. Prefer ProxyJump above. If you must forward an agent, only do so to hosts you fully trust, scope it to specific hosts in ~/.ssh/config (ForwardAgent yes under a single Host entry, never globally), require confirmation on each use by adding keys with ssh-add -c, and consider ssh-add -t <seconds> to auto-expire keys.

Debugging SSH Agent Issues: Increase verbosity to see detailed debugging output:

bash
ssh-add -v ~/.ssh/id_ed25519
ssh -vvv user@host

Look for lines mentioning "SSH_AUTH_SOCK" or "agent" to diagnose agent-related issues.

Frequently asked questions

What does "Could not open a connection to your authentication agent." mean?
SSH uses an agent process to securely hold your private keys in memory and provide them to SSH clients when needed for authentication. When you run ssh-add or try to authenticate via SSH (for example with Git), the SSH client looks for the agent via the SSH_AUTH_SOCK environment variable. If the agent isn't running or that variable isn't set, you get this error.
How do I fix "Could not open a connection to your authentication agent."?
"Could not open a connection to your authentication agent" means the SSH agent isn't running or SSH_AUTH_SOCK isn't set. Start the agent with eval and add your key.
What causes "Could not open a connection to your authentication agent."?
SSH agent is not running in your current shell session SSH_AUTH_SOCK environment variable is not set or points to an invalid socket SSH agent was not started with eval (missing eval $(ssh-agent -s))
Is the "Could not open a connection to your authentication agent." error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading