AWS Tips and Tricks
ssh-add command results in ‘error connecting to agent’
ssh-add command results in ‘error connecting to agent’

ssh-add command results in ‘error connecting to agent’

If you have tried to run the ssh-add command (to enable port forwarding for instance) and have received the ‘error connecting to agent’ message, you are using Windows 10 ssh and need to enable the ssh-agent service in order to setup agent forwarding.

You may see this error message if you are using Windows 10 and have multiple installations of ssh on your machine. This could occur if you have installed Git for Windows. If you have installed cmder, you may have installed Git for Windows without realizing it.

The first thing you need to do is determine which version of ssh you are using. Open a command prompt and run the following:

> which ssh-agent

If the response is /c/Windows/System32/OpenSSH/ssh-agent, this means you are using the Windows 10 version of ssh. You will need to remove it from your PATH environment variable IF you want to use the Git For Windows version installed with cmder.

The rest of this post assumes you want to stick with the Windows 10 version of ssh.

You will need to start by enabling the ssh-agent service using PowerShell. If you don’t already have PS short-cutted on your machine, you can find it easily by searching for PowerShell.

Run as Administrator and once in PowerShell, run the following:

> Get-Service ssh-agent | Set-Service -StartupType Automatic

Once that is done, you should verify that ssh-agent is indeed set for automatic startup:

> Get-Service | select -property name,starttype

Scroll up to find the ssh-agent service and verify it is set for automatic.

Go back to your command prompt window, ensure you are in the directory which contains your .pem file, and add to ssh:

> ssh-add “.\<your-pemfile-name>.pem”

You may then setup agent forwarding with the following:

> ssh -A ec2-user@<public IP of your bastion host>

If you see, ‘warning: agent returned different signature type ssh-rsa (expected rsa-sha2-512)’, Windows is out of date but you should be able to continue without issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami