install openssh on windows

The following are instructions on how to setup OpenSSH on various Windows server versions. This is great if you come from a Linux background and are very used to SSH for accessing machines.

Windows Server 2019

First run PowerShell as Administrator.

Next install SSH and SSHD for Windows:

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

Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

Confirm installation by ensuring rules are correct:

Get-NetFirewallRule -Name *ssh*

Windows Server 2016/2012R2

Download zip from github:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -OutFile

Extact it (for 2012R2):

[System.IO.Compression.ZipFile]::ExtractToDirectory('', 'C:\Program Files\')

Extract it (for 2016):

Expand-Archive .\ 'C:\Program Files\'

Install it:

cd 'C:\Program Files\OpenSSH-Win64\'
mkdir C:\ProgramData\ssh
.\ssh-keygen.exe -A
# select A to all questions
Start-Service -Name sshd
Set-Service -Name "sshd" -StartupType automatic

Confirm it is running:

Get-WMIObject win32_service -Filter "name = 'sshd'"

Open up firewall:

netsh advfirewall firewall add rule name="Open Port 22" dir=in action=allow protocol=TCP localport=22