PowerShell: unable to start ssh-agent service, error :1058

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# PowerShell: unable to start ssh-agent service, error :1058

The error "unable to start ssh-agent service, error: 1058" occurs when SSH-Agent is installed on Windows, but the ssh-agent service has not been started.

To solve the error, start PowerShell as an administrator and start the service manually using a command or the GUI.

powershell unable to start ssh agent service error 1058

Here is the complete stack trace.

shell
unable to start ssh-agent service, error :1058 Start-Service : Service 'OpenSSH Authentication Agent (ssh-agent)' cannot be started due to the following error: Cannot start service ssh-agent on computer '.'. Access is denied. At line:1 char:1 + Start-service ssh-agent + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand

First, start PowerShell as an administrator.

  1. Click on the Search bar and type PowerShell.

  2. Right-click on the PowerShell application and click "Run as administrator".

run powershell as administrator

  1. Issue the following command.
PowerShell
Get-Service ssh-agent

get service ssh agent

The Get-Service command will display the status of the OpenSSH Authentication Agent.

The status will most likely be Stopped as shown in the screenshot.

  1. Check the start type of the ssh-agent service.
PowerShell
Get-Service ssh-agent | Select StartType

get start type of ssh agent service

The start type of the service will most likely be Disabled as shown in the screenshot.

If you get the error 'Get-Service' is not recognized as an internal or external command, operable program or batch file, it means that you aren't currently in a PowerShell session.

When you run the start-ssh-agent command in PowerShell, it switches you to CMD.

You have to type exit and press Enter to exit the CMD session to be able to issue the Get-Service command.

CMD
exit # Now issue the Get-Service command Get-Service ssh-agent | Select StartType
  1. Set the start type of the ssh-agent service to Manual by running the following command.
PowerShell
Get-Service -Name ssh-agent | Set-Service -StartupType Manual

set start type of ssh agent to manual

When the start type of the ssh-agent service is set to Manual, the service is automatically started when you issue the ssh-agent command.

Note that PowerShell has to be started as an administrator for the command to work, otherwise, you'd get a permissions error.

Try to issue the Start-Service ssh-agent command.

PowerShell
Start-Service ssh-agent

start service ssh agent

You can also use the ssh-agent.exe command to start ssh-agent.

PowerShell
ssh-agent.exe

If that didn't work, try setting the start type of the service using the graphic user interface.

# Setting the Start type of ssh-agent using the GUI

To set the start type of the ssh-agent service to Manual using the GUI:

  1. Click on the search field and type Services.

search services

  1. Start the Services application.

  2. Scroll down to the OpenSSH Authentication Agent service.

scroll down to openssh authentication agent service

  1. Set the Startup type to Manual and click on Apply and OK.

set startup type to manual

Try to issue the Start-Service ssh-agent command.

PowerShell
Start-Service ssh-agent

start service ssh agent

You can also use the ssh-agent.exe command to start ssh-agent.

PowerShell
ssh-agent.exe

If that didn't work either, try setting the Startup type to Automatic.

set startup type to automatic

If the error persists, start PowerShell as an administrator:

  1. Click on the Search bar and type PowerShell.

  2. Right-click on the PowerShell application and click "Run as administrator".

run powershell as administrator

  1. Set the start type of the ssh-agent service to Automatic.
PowerShell
Get-Service -Name ssh-agent | Set-Service -StartupType Automatic

Try to issue the Start-Service ssh-agent command.

PowerShell
Start-Service ssh-agent

start service ssh agent

You can also use the ssh-agent.exe command to start ssh-agent.

PowerShell
ssh-agent.exe

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.