DEV Community

Cover image for Starting `ssh-agent` in Windows PowerShell
Paul Cochrane 🇪🇺
Paul Cochrane 🇪🇺

Posted on • Originally published at peateasea.de on

Starting `ssh-agent` in Windows PowerShell

Originally published on peateasea.de.

As someone who works mostly on Linux, there seem to be a multitude of issues for me to stumble over when having to use Windows. Using ssh in Windows PowerShell for instance: the ssh-agent service is disabled by default. Thus Git commands don’t work “out of the box” as one might expect. Here’s how to kick it in the guts and get things working.

git clone isn’t working. How come?

Let’s say you’re using Windows PowerShell and you want to clone a Git upstream repository. You run git clone but find you don’t have the permissions to access the repository. After promptly thinking “Yeah I do!”, you realise you’ve forgotten to add your SSH key to the SSH agent. Oops. 🤦

Your first instinct is to start an SSH agent and add your SSH key to it. You run ssh-agent from the command line only to run into the next problem:

PS C:\Users\cochrane> ssh-agent
unable to start ssh-agent service, error :1058
Enter fullscreen mode Exit fullscreen mode

Dumping the error message into Google your favourite search engine, you might stumble across an appropriate StackOverflow answer.

Here’s my take on analysing the situation and resolving the problem. Also, by putting the notes here I’m more likely to find them later myself. 😁

ssh-agent disabled by default

You can find the status of the ssh-agent service via the Get-Servicecommand:

PS C:\Users\cochrane> Get-Service ssh-agent

Status Name DisplayName
------ ---- -----------
Stopped ssh-agent OpenSSH Authentication Agent
Enter fullscreen mode Exit fullscreen mode

where we see a stopped ssh-agent service. But it’s worse than that the service is also disabled:

PS C:\Users\cochrane> Get-Service ssh-agent | Select StartType

StartType
---------
 Disabled
Enter fullscreen mode Exit fullscreen mode

What to do?

Asking an adult for help

The solution requires admin privileges. Right-click on the Windows PowerShell icon and select “Run as administrator”.

To enable the service, I set its StartupType to Manual:

PS C:\WINDOWS\system32> Get-Service -Name ssh-agent | Set-Service -StartupType Manual
PS C:\WINDOWS\system32> Get-Service ssh-agent | Select StartType

StartType
---------
   Manual
Enter fullscreen mode Exit fullscreen mode

Now I need to start the service with the Start-Service command:

PS C:\WINDOWS\system32> Start-Service ssh-agent
Enter fullscreen mode Exit fullscreen mode

How’re things looking?

PS C:\WINDOWS\system32> Get-Service ssh-agent

Status Name DisplayName
------ ---- -----------
Running ssh-agent OpenSSH Authentication Agent
Enter fullscreen mode Exit fullscreen mode

All good, it’s running. Also, it should now be available to run the next time I have to use Windows.

One final check

Let’s check that everything works (as a normal user) by adding my key to the SSH agent:

PS C:\Users\cochrane> ssh-add
Enter passphrase for C:\Users\cochrane/.ssh/id_rsa:
Enter fullscreen mode Exit fullscreen mode

Yup, looking good. Now I can get back on with my day.

Top comments (0)