Starting `ssh-agent` in Windows PowerShell
Tags: windows, git, ssh
Published: 2024-04-26 12:39:37

---
title: Starting `ssh-agent` in Windows PowerShell
published: true
date: 2024-03-26 23:00:00 UTC
tags: Windows,Git,SSH
canonical_url: https://peateasea.de/starting-ssh-agent-in-windows-powershell/
cover_image: https://peateasea.de/assets/images/windows-powershell-alert-ssh.png
---

*Originally published on [peateasea.de](https://peateasea.de/starting-ssh-agent-in-windows-powershell/).*

As someone who works mostly on [Linux](https://en.wikipedia.org/wiki/Linux), there seem to be a multitude of issues for me to stumble over when having to use Windows. Using `ssh` in [Windows PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/what-is-windows-powershell?view=powershell-7.4) for instance: the `ssh-agent` service is disabled by default. Thus [Git](https://git-scm.com/) commands don’t work “out of the box” as one might expect. Here’s how to [kick it in the guts](https://www.youtube.com/watch?v=2MeCLILELNc) 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. :facepalm:

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
```

Dumping the error message into ~~Google~~ your favourite search engine, you might stumble across [an appropriate StackOverflow answer](https://stackoverflow.com/a/53606760).

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. :grin:

## `ssh-agent` disabled by default

You can find the status of the `ssh-agent` service via the `Get-Service`command:

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

Status Name DisplayName
------ ---- -----------
Stopped ssh-agent OpenSSH Authentication Agent
```

where we see a stopped `ssh-agent` service. But [it’s worse than that](https://youtu.be/FCARADb9asE?t=75) the service is also disabled:

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

StartType
---------
 Disabled
```

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
```

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

```
PS C:\WINDOWS\system32> Start-Service ssh-agent
```

How’re things looking?

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

Status Name DisplayName
------ ---- -----------
Running ssh-agent OpenSSH Authentication Agent
```

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:
```

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