Fixing the "error: communication with agent failed" for ssh-add on Windows

beginner🪟 Windows2026-07-22| Windows 10, Windows 11, OpenSSH Client

Error Message

error: communication with agent failed
#ssh#git#windows#devops#powershell

The Problem

Nothing stalls a workflow like a sudden SSH error. You try to add your private key to the agent so you can push code or log into a server, but instead of a success message, you get this:

error: communication with agent failed

This usually pops up in PowerShell, Command Prompt, or the integrated terminal in VS Code. It means your keys aren't being cached. As a result, you're stuck typing your passphrase every single time you interact with a remote Git repository.

Why This Happens

The ssh-add command is just a messenger. It needs to talk to a background process called the OpenSSH Authentication Agent (ssh-agent). This service keeps your decrypted keys in your RAM so you don't have to keep re-entering passwords.

On Windows, this agent is a System Service. While Windows includes the OpenSSH client by default, the ssh-agent service is often set to "Disabled" out of the box. When you run the command, it looks for a "named pipe" connection to the service. If the service isn't running, the connection drops, and you get the error.

Fix 1: The Fast PowerShell Method (Recommended)

Using PowerShell is the most direct way to fix this. You'll need to change the service startup type to "Automatic" and kickstart the process. This takes about 10 seconds.

1. Open PowerShell as Administrator

Press the Win key, type "PowerShell," right-click the result, and choose Run as Administrator. You need these elevated rights to modify system services.

2. Check the Service Status

See if the service is actually the culprit by running:

Get-Service ssh-agent

In most cases, you'll see the Status is "Stopped" and the StartType is "Disabled".

3. Enable and Start

Run these two commands to get things moving:

# Set the service to start automatically whenever Windows boots
Set-Service -Name ssh-agent -StartupType Automatic

# Start the service immediately
Start-Service ssh-agent

Now, try adding your key again. It should work instantly:

ssh-add ~/.ssh/id_rsa

Fix 2: Using the Windows Services Manager (GUI)

If you prefer clicking through menus rather than typing commands, you can use the standard Windows management tools.

  • Press Win + R, type services.msc, and hit Enter.
  • Find OpenSSH Authentication Agent in the list.
  • Right-click it and choose Properties.
  • Set the Startup type to Automatic.
  • Click Start. The status bar should fill up in a second or two.
  • Click Apply and close the window.

Special Note for Git Bash Users

Git Bash (MinGW64) sometimes ignores the Windows system service. If you've started the service but Git Bash still complains, you might need to start a local instance of the agent for that specific window.

Run this command inside Git Bash:

eval $(ssh-agent -s)

This manually initializes the agent and sets the SSH_AUTH_SOCK environment variable for your current session.

Confirming the Fix

To make sure everything is running smoothly, ask the agent to list your currently loaded keys:

ssh-add -l

If the agent is active but empty, it will tell you: "The agent has no identities." That’s a good sign—it means the communication channel is open. If you see a long string of numbers and letters (the fingerprint), your key is successfully loaded and ready to use.

Pro-Tips for SSH on Windows

  • Keep it Automatic: Don't set the service to "Manual." If you do, it won't start after a reboot, and you'll find yourself back here reading this guide in a week.
  • Watch for Conflicts: If you use PuTTY or Pageant, they can sometimes fight over which agent handles your keys. If things stay buggy, try closing Pageant to see if the native Windows OpenSSH starts working.
  • File Permissions: Windows is picky about security. If the agent is running but won't accept your key, right-click your id_rsa file, go to Security > Advanced, and ensure your user account is the only one with access.

Related Error Notes