What the "ssh-agent not running" Error Means
The error ssh-agent not running (or Could not open a connection to your authentication agent) occurs when commands that work with SSH keys (e.g., ssh-add, git over SSH) cannot find a running ssh-agent process and its associated Unix socket.
Symptoms:
- Running
ssh-add -lorssh-add ~/.ssh/your_keyfails with the specified error. git clone,git push, orgit pulloperations over SSH prompt for a password and may fail.- Connecting to a remote server via
ssh user@hostmight require a password instead of using the key.
This means your system doesn't have a working "storage" for decrypted private SSH keys in memory.
Common Causes
- The agent is not set to auto-launch. In modern versions of macOS (starting with Catalina),
zshis the default shell, and the SSH agent might not be added to autostart when a new user is created or after resetting settings. - The
SSH_AUTH_SOCKenvironment variable is not set. Even if the agent is running, the terminal needs to know which socket to connect to. This variable can be lost when restarting the terminal or if the shell profile isn't configured. - Issues with
launchdmanagement. The SSH agent on macOS is managed by the systemlaunchdmanager. If the configuration in~/Library/LaunchAgents/is corrupted or missing, the agent won't start. - Conflict with another agent. Another SSH agent (e.g., from a key manager) might be running on the system, causing a conflict or socket hijacking.
Solution 1: Manually Start the Agent (Quick Fix)
This solves the problem for the current terminal session.
- Start the agent and get the environment variables:
Theeval "$(ssh-agent -s)"ssh-agent -scommand outputs commands to set theSSH_AGENT_PID(process ID) andSSH_AUTH_SOCK(socket path) variables.evalexecutes them in the current shell.

macOS terminal showing the output of the ssh-agent command and setting environment variables
- Add your SSH key to the agent:
If you have a different key type (e.g., Ed25519) or a different filename, specify the correct path. If the key is password-protected, the system will prompt for it once.ssh-add ~/.ssh/id_rsa
After this, ssh-add -l and git operations should work.
Solution 2: Configure Autostart via Shell Profile (Permanent Solution)
To have the agent start automatically every time you open a terminal, you need to add initialization to your shell's configuration file.

.zshrc configuration file with ssh-agent autostart settings
- Determine which shell you are using:
echo $SHELL
The output will be/bin/zsh(default since Catalina) or/bin/bash. - Open the corresponding profile file in a text editor:
- For zsh:
nano ~/.zshrc - For bash:
nano ~/.bash_profile(or~/.bashrc)
- For zsh:
- Add the following lines to the end of the file:
# Start ssh-agent if it's not already running if [ -z "$SSH_AUTH_SOCK" ] ; then eval "$(ssh-agent -s)" fi
This block checks if theSSH_AUTH_SOCKvariable already exists. If not, it starts the agent and exports the variables. - Save the file (
Ctrl+O,Enter,Ctrl+Xin nano) and apply the changes:source ~/.zshrc # or source ~/.bash_profile
Or simply open a new terminal window. - Add the key once (if you haven't already):
ssh-add ~/.ssh/id_rsa.
Solution 3: Use the macOS Keychain Manager
macOS has a built-in system keychain that can store SSH keys. This is the most integrated method.

Command to add an SSH key to macOS Keychain using ssh-add -K
- Add the key to the keychain on first use:
ssh-add -K ~/.ssh/id_rsa
The-K(uppercase K) flag adds the key to the macOS Keychain. After this, the system will automatically start the agent and load the key from the keychain at login. For macOS 12.0 (Monterey) and newer, you can usessh-add --apple-use-keychain ~/.ssh/id_rsa. - Ensure your
~/.ssh/config(if it exists) doesn't override this. Recommended config for keychain integration:Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa
Solution 4: Check and Fix Socket Permissions
Sometimes the issue is incorrect permissions on the /tmp directory or the agent's socket.
- Check if the socket exists:
ls -l $SSH_AUTH_SOCK
If the variable is empty or the path doesn't exist, the agent didn't create the socket. - Restart the agent manually (Solution 1) and check again.
If the problem persists, check permissions on temporary files:
sudo chmod 1777 /tmp
These are standard permissions for/tmp(sticky bit). Be cautious when modifying system directories.
Prevention
- Always configure autostart via your shell profile (Solution 2) or use the keychain (Solution 3).
- After a macOS update or a shell change (e.g., from bash to zsh), verify that your profile file (
.zshrc) contains thessh-agentsettings. - Do not manually delete socket files in
/tmp/(e.g.,/tmp/ssh-*/agent.*). This can leave "stale" references. It's better to restart the agent. - Regularly update your system:
softwareupdate --install --allto receive fixes for security components andlaunchd.