Share via

Windows 11 Services does not remember settings for OpenSSH Server

James Rome 36 Reputation points
2022-10-09T12:53:24.85+00:00

Every time I do a Windows Update, after reboot, Services comes up with OpenSSH Server off and start manual . I had previously set startup to be automatic. I files 5 bug reports with no fixes or response.

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments

Answer accepted by question author

MotoX80 37,686 Reputation points
2022-10-10T18:09:06.32+00:00

Is the name of your pc "server2"? If not, that code isn't going to work. If you are running the command on the target system, you don't need to specify the computername. And if the status of the service "is equal to running", then setting it to running isn't going to do anything. You need to test for "not equal".

$servicename = "sshd"        # or use the display name "OpenSSH SSH Server"  
  
$service = Get-Service -Name $servicename   
  
if ($service.Status -ne 'Running') {  
    "Starting $servicename"  
    $service | Set-Service -Status Running  
}  
  
if ($service.StartType -ne 'Automatic') {  
    "Setting $servicename to start=auto"  
    $service | Set-Service -StartupType Automatic  
}  

Windows update should not change the startup type of that service. There must be something else going on with your pc. After you install an update, and BEFORE you reboot, check the status of the service. Did it revert to manual?

Also check the system and application eventlogs and see if there are any events that refernece the service.

I have installed sshd on my win11 laptop I will see if my pc has the same issue the next time that I install any updates.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Limitless Technology 40,101 Reputation points
    2022-10-10T14:29:02.217+00:00

    Hi,

    Thank you for your question and reaching out.

    I understand that you're having issues with the Windows Updates causing the OpenSSH Server to be off even if you set it to Automatic. This is probably the default setting for the OpenSSH Server recommended by Windows system which is why it is being set back to Manual instead of Automatic every after update.

    You may set it to Automatic using this PowerShell code and test if it works by installing a new update:

    $servicename = 'spooler'
    $server = 'server2'

    $service = Get-Service -Name $servicename -ComputerName $server

    if ($service.Status -eq 'Running') {
    $service | Set-Service -Status Running
    }

    if ($service.StartType -eq 'Automatic') {
    $service | Set-Service -StartupType Automatic
    }

    -------------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    Was this answer helpful?

    1 person found this answer helpful.

  2. James Rome 36 Reputation points
    2022-10-10T16:06:06.777+00:00

    Alas, it did not work. Maybe I did not set it correctly?

    PS C:\WINDOWS\system32> $servicename = 'OpenSSH SSH Server'

    > $server = 'server2'
    >
    > $service = Get-Service -Name $servicename -ComputerName $server
    >
    > if ($service.Status -eq 'Running') {
    > $service | Set-Service -Status Running
    > }
    >
    > if ($service.StartType -eq 'Automatic') {
    > $service | Set-Service -StartupType Automatic
    > }

    Get-Service : Cannot find any service with service name 'OpenSSH SSH Server'.
    At line:4 char:12

    • $service = Get-Service -Name $servicename -ComputerName $server
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ObjectNotFound: (OpenSSH SSH Server:String) [Get-Service], ServiceCommandException
    • FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

    PS C:\WINDOWS\system32> $servicename = 'sshd.exe'

    > $server = 'server2'
    >
    > $service = Get-Service -Name $servicename -ComputerName $server
    >
    > if ($service.Status -eq 'Running') {
    > $service | Set-Service -Status Running
    > }
    >
    > if ($service.StartType -eq 'Automatic') {
    > $service | Set-Service -StartupType Automatic
    > }

    Get-Service : Cannot find any service with service name 'sshd.exe'.
    At line:4 char:12

    • $service = Get-Service -Name $servicename -ComputerName $server
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ObjectNotFound: (sshd.exe:String) [Get-Service], ServiceCommandException
    • FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.