Windows/SSHD

From Omnia
Jump to navigation Jump to search

Install OpenSSH

Install the Inbox Version: [1]

# In Admin window:
# Verify Admin
(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
# Verify Capabilities
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# alternative
Add-WindowsCapability -Online -Name OpenSSH.Client*
# alternative
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
# alternative
Add-WindowsCapability -Online -Name OpenSSH.Server*

OR Install OpenSSH Preview/Beta Version with WinGet

# Preview version
winget install Microsoft.OpenSSH.Preview
# Beta version
winget install Microsoft.OpenSSH.Beta

Start the sshd service

Start-Service sshd

OPTIONAL but recommended, Set the service to start automatically:

Set-Service -Name sshd -StartupType Automatic

Open firewall: (owershell)

# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
# alternative
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Fix SSH Keys: (comment out these two lines at the bottom of the config file)

C:\ProgramData\ssh\sshd_config
#Match Group administrators
#       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

Restart service:

Restart-Service sshd