Last active
September 4, 2023 12:39
-
-
Save sheepla/77427fdbdd2716c383524d771cbb95c5 to your computer and use it in GitHub Desktop.
Install OpenSSH server for Windows and configure to manage Windows computer remotely
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
<# | |
.DESCRIPTION | |
Install OpenSSH and configure to manage Windows computer remotely. | |
.LINK | |
https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview | |
#> | |
Write-Host "Installing OpenSSH..." | |
Get-WindowsCapability -Online | Where-Object {$_.Name -ILike "openssh*"} | ForEach-Object { | |
Write-Host " Adding Windows capability: $($_.Name)" | |
Add-WindowsCapability -Online -Name $_.Name | |
} | |
Write-Host "Starting sshd service..." | |
Start-Service sshd | |
Write-Host "Configureing to start sshd service automatically..." | |
Set-Service -Name sshd -StartupType "Automatic" | |
Write-Host "Checking firewall rule..." | |
$firewallRule = Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" | | |
Select-Object -Property @("Name", "Enabled") | |
if ($null -ne $firewallRule) | |
{ | |
Write-Output $firewallRule | |
} | |
Write-Host "Finished to install OpenSSH! Please connect this computer with the following command:" | |
Write-Host " ssh ${env:UserName}@${env:ComputerName}" | |
Write-Host "Configuration file is here:$([IO.Path]::Combine($env:ProgramData, "ssh", "sshd_config"))" | |
Write-Host "Configureing default shell..." | |
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
c.f.