Skip to content

Instantly share code, notes, and snippets.

@stephenfuqua
Last active February 17, 2018 20:35
Show Gist options
  • Save stephenfuqua/46332c46741d94dc216e1332b437012c to your computer and use it in GitHub Desktop.
Save stephenfuqua/46332c46741d94dc216e1332b437012c to your computer and use it in GitHub Desktop.
$toolsDir = "c:\tools"
$sshZip = "$toolsDir\OpenSSH-Win64.zip"
$sshDir = "$toolsDir\OpenSSH-Win64"
$install = "$sshDir\install-sshd.ps1"
# Download OpenSSH
$url = "https://github.com/PowerShell/Win32-OpenSSH/releases/download/v1.0.0.0/OpenSSH-Win64.zip"
Invoke-WebRequest -Uri $url -OutFile $sshZip
# Unzip the OpenSSH archive
Expand-Archive -LiteralPath $sshZip -DestinationPath $toolsDir
# Install SSH
Invoke-Expression $install
# Absolutely necessary: the users group must have appropriate permissions on the OpenSSH folder
$acl = Get-Acl $sshDir
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule(".\users","ReadAndExecute,Synchronize", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($ar)
Set-Acl $sshDir $acl
# Open firewall and set service startup policy
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Set-Service sshd -StartupType Automatic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment