Skip to content

Instantly share code, notes, and snippets.

@bxtp4p
Created December 13, 2017 22:42
Show Gist options
  • Save bxtp4p/6beea70fabe59f57d7877f1cd095e447 to your computer and use it in GitHub Desktop.
Save bxtp4p/6beea70fabe59f57d7877f1cd095e447 to your computer and use it in GitHub Desktop.
Installs OpenSSH on Windows. Also configures Powershell to be the default shell for ssh sessions.
Invoke-WebRequest -OutFile OpenSSH-Win64.zip https://github.com/PowerShell/Win32-OpenSSH/releases/download/0.0.24.0/OpenSSH-Win64.zip;
Expand-Archive .\OpenSSH-Win64.zip;
$openSSHDir='C:\Program Files\OpenSSH';
md $openSSHDir;
mv .\OpenSSH-Win64\OpenSSH-Win64\* $openSSHDir;
powershell -ExecutionPolicy Bypass -File $openSSHDir\install-sshd.ps1;
$openSSHDir\ssh-keygen.exe -A;
powershell -ExecutionPolicy Bypass ". `'$openSSHDir\FixHostFilePermissions.ps1`' -Confirm:0";
New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName SSH;
Set-Service sshd -StartupType Automatic;
Set-Service ssh-agent -StartupType Automatic;
net start sshd;
New-ItemProperty -Name DefaultShell -Path HKLM:\SOFTWARE\OpenSSH -Force;
Set-ItemProperty -Name DefaultShell -Path HKLM:\SOFTWARE\OpenSSH -Value C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe;
@sgargel
Copy link

sgargel commented Jul 5, 2019

I needed to add [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 on top.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -OutFile OpenSSH-Win64.zip https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.0.0.0p1-Beta/OpenSSH-Win64.zip;
Expand-Archive .\OpenSSH-Win64.zip;
$openSSHDir='C:\Program Files\OpenSSH';
md $openSSHDir;
mv .\OpenSSH-Win64\OpenSSH-Win64\* $openSSHDir;
powershell -ExecutionPolicy Bypass -File $openSSHDir\install-sshd.ps1;
$openSSHDir\ssh-keygen.exe -A;
powershell -ExecutionPolicy Bypass ". `'$openSSHDir\FixHostFilePermissions.ps1`' -Confirm:0";
New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName SSH;
Set-Service sshd -StartupType Automatic;
Set-Service ssh-agent -StartupType Automatic;
net start sshd;
New-ItemProperty -Name DefaultShell -Path HKLM:\SOFTWARE\OpenSSH -Force;
Set-ItemProperty -Name DefaultShell -Path HKLM:\SOFTWARE\OpenSSH -Value C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment