Skip to content

Instantly share code, notes, and snippets.

@espresso3389
Last active October 27, 2025 07:52
Show Gist options
  • Select an option

  • Save espresso3389/b7c174bd8184c6030fff49dd52f1d9c2 to your computer and use it in GitHub Desktop.

Select an option

Save espresso3389/b7c174bd8184c6030fff49dd52f1d9c2 to your computer and use it in GitHub Desktop.
Enable SSH Server on Windows 11

NOTE: Open Administrative PowerShell (not pwsh.exe) and run the every steps below.

Install OpenSSH Server

Firstly check the actual component name:

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

Then, install the OpenSSH Server (in the case, OpenSSH.Server~~~~0.0.1.0):

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Automatically Start OpenSSH Server on Machine Startup

Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd

Create a Firewall Rule

if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
    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."
}

Prepare Needed Files

# Your client's public key
$authorizedKey="ssh-ed25519 AAAA...."

powershell Add-Content -Force -Path $env:ProgramData\ssh\administrators_authorized_keys -Value '''$authorizedKey'''
icacls.exe "$env:ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

Change Login Shell

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Users\kawasaki\AppData\Local\Microsoft\WindowsApps\pwsh.exe" -PropertyType String -Force

References

https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment