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.