Skip to content

Instantly share code, notes, and snippets.

@pizycki
Last active June 6, 2020 14:47
Show Gist options
  • Save pizycki/983bcbd618a2ad20969843ba87557263 to your computer and use it in GitHub Desktop.
Save pizycki/983bcbd618a2ad20969843ba87557263 to your computer and use it in GitHub Desktop.
Installs OpenSSH Server on Windows 10
# Run as Administrator
$openSshStatus = Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Server*'
if($openSshStatus[0].State -eq "NotPresent"){
Write-Output "OpenSSH server not detected. Processing to installation..."
$installResult = Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
if($installResult.Online -eq $true){
Write-Output "Installation succeeded."
}
} else {
Write-Output "OpenSSH server is already installed."
}
$sshd = Get-Service sshd # SSH Server deamon
if($sshd.Status -ne "Running"){
# Register
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup.
$fwRule = Get-NetFirewallRule -Name *ssh*
if($fwRule -eq $null) {
# There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled
# If the firewall does not exist, create one
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
}
Start-Service sshd
} else {
Write-Output "OpenSSH server is running."
}
# https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
# https://365adviser.com/powershell/install-use-openssh-windows-powershell-core-remoting-via-ssh/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment