How to install OpenSSH Server in Windows Server using PowerShell
Follow below steps to install OpenSSH Server in Windows Server using PowerShell.
Step 1 - Open Windows PowerShell from Windows Startmenu, by right-clicking it and selecting "Run as administrator". Run cmdlet Get-WindowsCapability, as shown below, to know the Windows OS capabilities related with SSH. We can see from the output that the OpenSSH client is installed and OpenSSH server is not installed, as shown below.
Step 2 - To install OpenSSH SSH Server using PowerShell, run Add-WindowsCapability cmdlet as shown below.
Step 3 - To start OpenSSH SSH Server service, run Start-Service PowerShell cmdlet, as shown below.
Step 4 - If you want OpenSSH SSH Server service to start automatically every time Windows Server Operating System starts, set OpenSSH SSH Server service Startup type as "Automatic", as shown below.
Step 5 - Create a Windows Firewall rule for sshd to allow inbound TCP connections to Port number 22, where SSH server listens by default. Use NewNetFirewallRule PowerShell cmdlet, as shown below.
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Step 6 - Finally, to view the Windows Firewall rule for sshd, run PowerShell cmdlet Get-NetFirewallRule as shown below.