Last active
June 6, 2020 14:47
-
-
Save pizycki/983bcbd618a2ad20969843ba87557263 to your computer and use it in GitHub Desktop.
Installs OpenSSH Server on Windows 10
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
# 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