Skip to content

Instantly share code, notes, and snippets.

@fabriciorsf
Created September 13, 2021 19:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fabriciorsf/b4744551a48a76f1ae6ecae597b2c488 to your computer and use it in GitHub Desktop.
Save fabriciorsf/b4744551a48a76f1ae6ecae597b2c488 to your computer and use it in GitHub Desktop.
## Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
## Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
cd ~/Downloads
New-Item -ItemType Directory -Force -Path ssh
cd ssh
## Set network connection protocol to TLS 1.2
## Define the OpenSSH latest release url
$url = 'https://github.com/PowerShell/Win32-OpenSSH/releases/latest/'
## Create a web request to retrieve the latest release download link
$request = [System.Net.WebRequest]::Create($url)
$request.AllowAutoRedirect=$false
$response=$request.GetResponse()
$source = $([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win64.zip'
## Download the latest OpenSSH for Windows package to the current working directory
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($source, (Get-Location).Path + '\OpenSSH-Win64.zip')
## The OpenSSH-Win64.zip file should now be in your current working directory. Verify this by running the command below.
#Get-ChildItem *.zip
## Extract the ZIP to a temporary location
Expand-Archive -Path .\OpenSSH-Win64.zip -DestinationPath ($env:temp) -Force
## Move the extracted ZIP contents from the temporary location to C:\Program Files\OpenSSH\
Move-Item "$($env:temp)\OpenSSH-Win64" -Destination "$($env:ProgramFiles)\OpenSSH\" -Force
## Unblock the files in C:\Program Files\OpenSSH\
Get-ChildItem -Path "$($env:ProgramFiles)\OpenSSH\" | Unblock-File
& "$($env:ProgramFiles)\OpenSSH\install-sshd.ps1"
## changes the sshd service's startup type from manual to automatic.
Set-Service sshd -StartupType 'Automatic'
## starts the sshd service.
Start-Service sshd
## Confirm the firewall rule is configured. It should be created automatically by setup.
#Get-NetFirewallRule -Name *ssh*
## creates a firewall rule called Allow SSH that allows all inbound TCP traffic destined to port 22.
New-NetFirewallRule -Name sshd -DisplayName 'SSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment