This error occurs when SSH cannot communicate with the ssh-agent service, typically because the agent isn't running. Restart the agent using eval "$(ssh-agent -s)" to resolve the issue.
The SSH agent is a background service that manages your SSH keys and handles authentication. When you run ssh-add or attempt SSH operations, they communicate with the agent through a Unix socket. This error means the SSH client cannot connect to that socket because the agent process isn't running or the socket path is incorrect. The agent is essential for SSH key-based authentication, allowing you to authenticate without entering passwords. Without it, ssh-add cannot add keys, and SSH connections may fail if not properly configured.
Run the appropriate command for your shell to start the SSH agent:
For bash/zsh:
eval "$(ssh-agent -s)"For tcsh/csh:
eval `ssh-agent -c`For fish:
eval (ssh-agent -c)This command starts the agent in the background and sets the SSH_AUTH_SOCK and SSH_AGENT_PID environment variables in your current session. You should see output like:
Agent pid 12345Check that SSH_AUTH_SOCK is set and points to a valid socket:
echo $SSH_AUTH_SOCKYou should see a path like /tmp/ssh-XXXXXXXXXX/agent.xxxxx (on Linux/macOS) or similar. If empty, the agent didn't start properly.
Also verify the agent process is running:
ps aux | grep ssh-agentNow that the agent is running, add your private key:
ssh-add ~/.ssh/id_rsaReplace ~/.ssh/id_rsa with your actual private key path if different. If your key is passphrase-protected, you'll be prompted to enter it once. After that, the agent holds the key in memory and uses it for authentication automatically.
Verify the key was added:
ssh-add -lTo avoid starting the agent manually every time you open a new shell, add it to your shell's startup file:
For bash (add to ~/.bashrc):
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)" > /dev/null
fiFor zsh (add to ~/.zshrc):
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)" > /dev/null
fiFor fish (add to ~/.config/fish/config.fish):
if test -z $SSH_AUTH_SOCK
eval (ssh-agent -c)
endAfter adding the code, reload your shell configuration:
source ~/.bashrc
# or
source ~/.zshrcFor GNOME/KDE desktop users: If you're using GNOME or KDE, your desktop environment may manage ssh-agent through GNOME Keyring or KDE Wallet instead. This can cause SSH_AUTH_SOCK to point to a different location. If you experience persistent issues, you can disable the desktop's agent and use the standalone ssh-agent instead.
For oh-my-zsh users: If you use oh-my-zsh with the ssh-agent plugin, ensure you haven't enabled agent-forwarding with zstyle :omz:plugins:ssh-agent agent-forwarding on, as this can interfere with local agent functionality.
SSH_AUTH_SOCK in containers/remote environments: When using SSH agent forwarding to Docker containers, Kubernetes pods, or remote machines via SSH, the agent socket path must be forwarded correctly. The socket is specific to your local system and isn't directly accessible in remote environments—you need to explicitly forward it using -v flags in Docker or -R flags in SSH.
Agent forwarding security: Never forward your SSH agent to untrusted systems, as having access to the agent socket grants access to all your SSH keys.
Load key "/home/user/.ssh/id_rsa": invalid format
How to fix 'Load key invalid format' in SSH
Bad owner or permissions on /home/user/.ssh/config
How to fix "Bad owner or permissions on .ssh/config" in SSH
Connection closed by UNKNOWN port 65535
How to fix 'Connection closed by UNKNOWN port 65535' in SSH
Offending ECDSA key in /home/user/.ssh/known_hosts:line
How to fix "Offending ECDSA key in known_hosts" in SSH
bind: Address already in use
How to fix "bind: Address already in use" in SSH