How to install OpenSSH on Windows Server 2016 VM?
Windows Server 2016 VM must be created,
"allow_ping_ssh_rdp" security group must be allocated,
Floating IP address must be associated.
In the solution you will find how to:
Download and install OpenSSH,
Allow access in Windows Firewall,
Connect to Windows via SSH from Linux or Windows,
Accessing files via SFTP.
Download and install OpenSSH
Log in to your VM via RDP
Download the newest OpenSSH server from GitHub ( https://github.com/PowerShell/Win32-OpenSSH/releases )
In our case it is v22.214.171.124p1-Beta, 64-bit version.
If you can not download the file you can change security settings.
Go to "Control Panel" → "Network and Internet" → "Internet Options" and choose "Security" tab.
Click the Custom level... button.
Find the "Downloads" section and change the "File download" option to "Enable" then click OK.
Confirm by clicking Yes then click Apply.
Now you can download the file.
Open the downloaded file and copy the "OpenSSH-Win64" folder to "C:\Program Files".
Go to "C:\Program Files\OpenSSH-Win64" and edit the "sshd_config_default" file.
Find and uncomment following lines by removing the "#" at the beginning then save the file.
#Port 22 #PasswordAuthentication yes
After the changes it should be:
Port 22 PasswordAuthentication yes
Now you have to modify system environment variable.
To do it run Windows PowerShell as administrator ...
... and type the following command:
setx PATH "$env:path;C:\Program Files\OpenSSH-Win64" -m
You should see the output "SUCCESS: Specified value was saved.".
Change to the OpenSSH directory and run the install script.
cd "C:\Program Files\OpenSSH-Win64"; .\install-sshd.ps1
Enable automatic startup and start "sshd" and "ssh-agent" services.
Set-Service sshd -StartupType Automatic; Set-Service ssh-agent -StartupType Automatic; Start-Service sshd; Start-Service ssh-agent
Allow access in Windows Firewall
We have to add new firewall rule to open port which we will use to connect via SSH, default is 22.
To add the rule just run the following command in Windows PowerShell.
New-NetFirewallRule -DisplayName "OpenSSH-Server-In-TCP" -Direction Inbound -LocalPort 22 -Protocol TCP -Action Allow
Connect to Windows via SSH
Connect to the VM by typing the following command in terminal. Remember to type your VM's IP address.
Type the password.
If you are connected you should be in Administrator's home directory.
From Windows (via Putty)
Open Putty and create new session. Complete the fields as below.
Host Name for IP address: Administrator@<your-vm-ip-address>
Connection type: SSH
Saved Sessions: <your-vm-name>
Click Save button.
Double click on your new saved session to connect then click Yes.
Now you are connected to your Windows VM via SSH.
Accessing files via SFTP
- WinSCP must be installed
Open WinSCP and click New Session.
Complete fields as below and click Save.
Host name: <your-vm-ip-address>
Port number: 22
User name: Administrator
Click OK. You can also save your password.
Confirm by clicking Yes.
Now you can browse your files.