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
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-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 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.
Top comments (0)