Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ybagheri/417a26e5288237b2fc96b21f6bc719c8 to your computer and use it in GitHub Desktop.
Save ybagheri/417a26e5288237b2fc96b21f6bc719c8 to your computer and use it in GitHub Desktop.
Install OpenSSH on Windows Server 2016
# Execute it with elevated permissions
# Description:
# This script install automatically the open-ssh feature and enable it
# enable tls1.2 for downloads
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# creating openssh folder and download the zip
mkdir c:\openssh-install
cd c:\openssh-install
#update the last version if you want the last release
Invoke-WebRequest -Uri "https://github.com/PowerShell/Win32-OpenSSH/releases/download/V8.6.0.0p1-Beta/OpenSSH-Win64.zip" -OutFile .\openssh.zip
Expand-Archive .\openssh.zip -DestinationPath .\openssh\
cd .\openssh\OpenSSH-Win64\
# required for enable the service
setx PATH "$env:path;c:\openssh-install\openssh\OpenSSH-Win64\" -m
# required for install the service
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
# required for execute remote connections
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
net start sshd
# auto enable for each restart machine
Set-Service sshd -StartupType Automatic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment