win2016-openssh.ps1
· 948 B · PowerShell
Raw
# Run as Admin in PowerShell
# Download and extract OpenSSH-Win64
mkdir C:\openssh-install
cd C:\openssh-install
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://github.com/PowerShell/Win32-OpenSSH/releases/latest/download/OpenSSH-Win64.zip" -OutFile .\openssh.zip
Expand-Archive .\openssh.zip -DestinationPath .\openssh\
Move-Item .\openssh\OpenSSH-Win64 "C:\Program Files\OpenSSH-Win64" -Force
# Add to system PATH
setx PATH "$env:path;C:\Program Files\OpenSSH-Win64\" -m
# Install the sshd + ssh-agent services
cd "C:\Program Files\OpenSSH-Win64"
powershell.exe -ExecutionPolicy Bypass -File .\install-sshd.ps1
# Generate host keys
mkdir C:\ProgramData\ssh
.\ssh-keygen.exe -A
# Fix file perms
.\FixHostFilePermissions.ps1 -Confirm:$false
# Service
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic
Start-Service sshd
Start-Service ssh-agent
| 1 | # Run as Admin in PowerShell |
| 2 | |
| 3 | # Download and extract OpenSSH-Win64 |
| 4 | mkdir C:\openssh-install |
| 5 | cd C:\openssh-install |
| 6 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
| 7 | Invoke-WebRequest -Uri "https://github.com/PowerShell/Win32-OpenSSH/releases/latest/download/OpenSSH-Win64.zip" -OutFile .\openssh.zip |
| 8 | Expand-Archive .\openssh.zip -DestinationPath .\openssh\ |
| 9 | Move-Item .\openssh\OpenSSH-Win64 "C:\Program Files\OpenSSH-Win64" -Force |
| 10 | |
| 11 | # Add to system PATH |
| 12 | setx PATH "$env:path;C:\Program Files\OpenSSH-Win64\" -m |
| 13 | |
| 14 | # Install the sshd + ssh-agent services |
| 15 | cd "C:\Program Files\OpenSSH-Win64" |
| 16 | powershell.exe -ExecutionPolicy Bypass -File .\install-sshd.ps1 |
| 17 | |
| 18 | # Generate host keys |
| 19 | mkdir C:\ProgramData\ssh |
| 20 | .\ssh-keygen.exe -A |
| 21 | |
| 22 | # Fix file perms |
| 23 | .\FixHostFilePermissions.ps1 -Confirm:$false |
| 24 | |
| 25 | # Service |
| 26 | Set-Service sshd -StartupType Automatic |
| 27 | Set-Service ssh-agent -StartupType Automatic |
| 28 | Start-Service sshd |
| 29 | Start-Service ssh-agent |