Install Microsoft OpenSSH.Server package from PowerShell and set SSHD service to Automatic

#Install Microsoft OpenSSH.Server package from PowerShell and set SSHD service to Automatic


#Just the code:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Get-Service -Name sshd|Set-Service -StartupType 'Automatic'
Get-Service -Name sshd|Start-Service

#The long story…

#Add OpenSSH Server capability to Windows 10 and Windows Server 2019

#OpenSSH Server needs to be installed via Remote Desktop Protocol (RDP) or from a local PowerShell session to allow incoming SSH connections and tunnels.

#OpenSSH Client is now included with Microsoft Windows 10 and Microsoft Windows Servers. This package only needs to be installed on the remote side of a tunnel. OpenSSH Client is required on the computer initiating the connections or tunnels and is installed by default in the latest version of Windows 10, Windows Server 2019 and Windows Server 2022.

#Add-WindowsCapability does not work for the OpenSSH.Server package via Enter-PSSession for some reason.

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

#Set the SSHD service to Automatic

Get-Service -Name sshd|Set-Service -StartupType 'Automatic'

#Start the SSHD service

Get-Service -Name sshd|Start-Service

#Use this command to verify that OpenSSH Client is installed

(Get-WindowsCapability -Online|? Name -like 'OpenSSH.Client*').State

#Verify the incoming Windows Firewall rules for OpenSSH Server were properly created

Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP"