-
-
Save inevity/a0d7b9f1c5ba5a813917b92736122797 to your computer and use it in GitHub Desktop.
Install OpenSSH on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#need powershell 7 /wtf 5.1 | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
function Unzip | |
{ | |
param([string]$zipfile, [string]$outpath) | |
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) | |
} | |
$url = 'https://github.com/PowerShell/Win32-OpenSSH/releases/latest/' | |
$request = [System.Net.WebRequest]::Create($url) | |
$request.AllowAutoRedirect=$false | |
$response=$request.GetResponse() | |
$file = $([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win64.zip' | |
$client = new-object system.Net.Webclient; | |
$client.DownloadFile($file ,"c:\\OpenSSH-Win64.zip") | |
Unzip "c:\\OpenSSH-Win64.zip" "C:\Program Files\" | |
mv "c:\\Program Files\OpenSSH-Win64" "C:\Program Files\OpenSSH\" | |
powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\OpenSSH\install-sshd.ps1" | |
netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22 | |
# New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | |
net start sshd | |
Set-Service sshd -StartupType Automatic | |
Set-Service ssh-agent -StartupType Automatic | |
cd "C:\Program Files\OpenSSH\" | |
Powershell.exe -ExecutionPolicy Bypass -Command '. .\FixHostFilePermissions.ps1 -Confirm:$false' | |
$registryPath = "HKLM:\SOFTWARE\OpenSSH\" | |
$Name = "DefaultShell" | |
$value = "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" | |
IF(!(Test-Path $registryPath)) | |
{ | |
New-Item -Path $registryPath -Force | |
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType String -Force | |
} ELSE { | |
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType String -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment