OpenSSH Server lets you securely run Command Prompt, PowerShell, and approved command-line tools on a Windows PC from another device over encrypted SSH. This procedure applies to Windows 11 and Windows 10 version 1809 (build 17763) or later. Install the built-in OpenSSH Server optional feature, start the
Expected results:
Look for this entry:
If the state is
Expected output includes:
A Windows restart is normally not required after this installation. If the command reports that a restart is required, restart before continuing.
Expected result:
The automatic startup setting means the SSH server resumes after a normal Windows restart.
You can also manage the service in the graphical interface:
Check it in elevated PowerShell:
Expected result:
If the rule does not exist, create it:
To undo that restriction and restore the rule to accept connections from any remote address:
Do not change the firewall rule if you are connected remotely through the same SSH session unless you have confirmed the new rule includes your current client address.
Use either:
Replace:
On the first connection, SSH displays the server host-key fingerprint and asks whether you want to continue. Verify that you intended to reach that PC, then type:
Enter the Windows account password when prompted. Password characters do not appear while you type.
A successful session usually ends at a prompt similar to:
Run these commands to verify the remote identity and working directory:
Type the following to end the session:
When prompted:
The
On the client, display the public key:
Copy the complete single line, paste it into
For an account that belongs to the local Administrators group, OpenSSH uses a shared administrator key file instead:
Test the key from the client:
Expected result: after unlocking the private key with its passphrase, the connection opens without asking for the Windows account password.
Add this line in the global portion of the file, before any
Save the file, validate the configuration, and restart the service:
The validation command should return no output. Now open a new terminal on the client and confirm that key authentication still works:
If it fails, use the still-open session or local console to restore password authentication:
First, confirm the feature state:
If the server remains
The server capability is not installed, or installation did not finish. Re-run:
Then restart Windows if the installation reports that it is required, and repeat:
Expected results:
Stop or reconfigure the conflicting application rather than changing SSH settings blindly.
From the client, test network reachability:
Verify locally that the account can sign in and that you are using the correct password. If you disabled password authentication, password prompts are expected to fail; use the configured private key or restore the backed-up
Public-key authentication returns
Use verbose client output to see whether the correct key is offered:
Check these common causes:
Then restart the service:
To restore access later:
To remove OpenSSH Server entirely, run elevated PowerShell:
Restart Windows if the removal reports that a restart is required or if the service had active connections.
sshd service, confirm the Windows Firewall rule for TCP port 22, and test a connection from a second device. For regular remote access, use a non-administrator account and then configure public-key authentication.Prerequisites and compatibility
Before starting, confirm the following:- You have a local account that belongs to the computer’s built-in Administrators group.
- The target PC runs Windows 10 version 1809 or newer, or any supported Windows 11 release.
- PowerShell is version 5.1 or later.
- The PC is powered on, connected to the network, and not sleeping when you intend to connect.
- You know the username and password for the account that will sign in remotely.
- A second PC, Mac, Linux device, or SSH-capable terminal is available for testing.
Code:
winver
$PSVersionTable.PSVersion
(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
winvershows Windows 10 version 1809 or later, or Windows 11.- PowerShell shows major version
5and minor version1or later. - The last command returns
True.
Warning: Enabling an SSH server creates a remote sign-in path to the PC. Do not forward TCP port 22 from your router to the internet unless you have deliberately restricted access, configured public-key authentication, and understand the exposure. For most home and office use, allow SSH only from the local network or a trusted VPN.
Primary procedure
1. Check whether OpenSSH Server is already installed
Open PowerShell as Administrator and run:Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'Look for this entry:
Code:
Name : OpenSSH.Server~~~~0.0.1.0
State : Installed
Installed, skip to step 3. If it is NotPresent, install it by using either Settings or PowerShell.2. Install OpenSSH Server
Windows 11 Settings method
- Open Start > Settings.
- Select System > Optional features.
- Under Add an optional feature, select View features.
- Search for OpenSSH Server.
- Select OpenSSH Server.
- Select Next > Add.
- Wait for the installation to finish.
Windows 10 Settings method
- Open Start > Settings.
- Select Apps > Apps & features.
- Select Optional features or Manage optional features.
- Select Add a feature.
- Search for OpenSSH Server.
- Select OpenSSH Server > Install.
- Wait for installation to complete.
PowerShell method for Windows 10 or Windows 11
Open PowerShell as Administrator and run:Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0Expected output includes:
Code:
Online : True
RestartNeeded : False
3. Start OpenSSH Server and make it start automatically
In elevated PowerShell, run:
Code:
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
Get-Service sshd
Code:
Status Name DisplayName
------ ---- -----------
Running sshd OpenSSH SSH Server
You can also manage the service in the graphical interface:
- Press Start and type
services.msc. - Open Services.
- Double-click OpenSSH SSH Server.
- Set Startup type to Automatic.
- Select Start if the service is not already running.
- Select OK.
4. Verify the firewall rule for SSH
OpenSSH Server normally creates and enables an inbound Windows Defender Firewall rule namedOpenSSH-Server-In-TCP. It allows inbound TCP connections on port 22.Check it in elevated PowerShell:
Code:
Get-NetFirewallRule -Name OpenSSH-Server-In-TCP |
Get-NetFirewallPortFilter |
Format-Table Protocol, LocalPort
Code:
Protocol LocalPort
-------- ---------
TCP 22
Code:
New-NetFirewallRule `
-Name 'OpenSSH-Server-In-TCP' `
-DisplayName 'OpenSSH Server (sshd)' `
-Enabled True `
-Direction Inbound `
-Protocol TCP `
-Action Allow `
-LocalPort 22
For example, to permit only devices on a trustedWarning: The default rule can permit SSH from networks assigned to applicable firewall profiles. If the PC is on a shared, public, or otherwise untrusted network, restrict the permitted source addresses before testing remote access.
192.168.50.0/24 LAN:Set-NetFirewallRule -Name OpenSSH-Server-In-TCP -RemoteAddress 192.168.50.0/24To undo that restriction and restore the rule to accept connections from any remote address:
Set-NetFirewallRule -Name OpenSSH-Server-In-TCP -RemoteAddress AnyDo not change the firewall rule if you are connected remotely through the same SSH session unless you have confirmed the new rule includes your current client address.
5. Find the server’s name and local IP address
On the Windows PC hosting OpenSSH Server, run:
Code:
hostname
ipconfig
- The computer name returned by
hostname, such asDESKTOP-ADMIN. - The IPv4 address listed for the active Ethernet or Wi-Fi adapter, such as
192.168.50.25.
6. Test SSH from another device
From another Windows device, open PowerShell or Windows Terminal and run:ssh [email][email protected][/email]Replace:
usernamewith the Windows account name on the SSH server.192.168.50.25with the server’s actual IPv4 address.
ssh domain\[email][email protected][/email]On the first connection, SSH displays the server host-key fingerprint and asks whether you want to continue. Verify that you intended to reach that PC, then type:
yesEnter the Windows account password when prompted. Password characters do not appear while you type.
A successful session usually ends at a prompt similar to:
desktop-admin\username@DESKTOP-ADMIN C:\Users\username>Run these commands to verify the remote identity and working directory:
Code:
whoami
hostname
cd
exitConfigure public-key sign-in
Public-key authentication avoids routine password entry and is strongly preferred before exposing SSH beyond a tightly controlled local network or VPN.7. Create an SSH key on the client device
On the device from which you will connect, open PowerShell and run:ssh-keygen -t ed25519 -a 64 -f $env:USERPROFILE\.ssh\id_ed25519When prompted:
- Press Enter to accept the displayed file location.
- Enter a strong passphrase. A passphrase protects the private key if the client device is lost or compromised.
Code:
%USERPROFILE%\.ssh\id_ed25519
%USERPROFILE%\.ssh\id_ed25519.pub
.pub file is the public key. It is safe to copy to the SSH server. Never copy, email, or place the private id_ed25519 file on the server.8. Add the public key to the Windows account on the server
For a standard, non-administrator account, sign in locally to the server as that user. Create the.ssh folder and authorized-keys file:
Code:
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.ssh"
notepad "$env:USERPROFILE\.ssh\authorized_keys"
Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub"Copy the complete single line, paste it into
authorized_keys, save the file, and close Notepad.For an account that belongs to the local Administrators group, OpenSSH uses a shared administrator key file instead:
C:\ProgramData\ssh\administrators_authorized_keysCopy the public key to a temporary text file on the server, for exampleWarning: Administrator SSH access gives the connecting account the same broad privileges it has locally. Use a standard account for ordinary administration where possible. If you configure an administrator key, preserve the required file permissions or key authentication can fail.
C:\Temp\id_ed25519.pub, then run elevated PowerShell:
Code:
New-Item -ItemType Directory -Force -Path "$env:ProgramData\ssh"
Get-Content C:\Temp\id_ed25519.pub |
Add-Content -Force -Path "$env:ProgramData\ssh\administrators_authorized_keys"
icacls.exe "$env:ProgramData\ssh\administrators_authorized_keys" `
/inheritance:r `
/grant "Administrators:F" `
/grant "SYSTEM:F"
ssh -i $env:USERPROFILE\.ssh\id_ed25519 [email][email protected][/email]Expected result: after unlocking the private key with its passphrase, the connection opens without asking for the Windows account password.
9. Disable password authentication only after key access works
On the server, open elevated PowerShell and back up the configuration:Warning: A configuration error or missing key can lock every SSH user out. Keep the existing password-authenticated SSH session open, start a second session to test the key, and ensure you retain local console access before changing this setting.
Code:
Copy-Item C:\ProgramData\ssh\sshd_config C:\ProgramData\ssh\sshd_config.backup
notepad C:\ProgramData\ssh\sshd_config
Match block:PasswordAuthentication noSave the file, validate the configuration, and restart the service:
Code:
C:\Windows\System32\OpenSSH\sshd.exe -t
Restart-Service sshd
ssh -i $env:USERPROFILE\.ssh\id_ed25519 [email][email protected][/email]If it fails, use the still-open session or local console to restore password authentication:
Code:
Copy-Item C:\ProgramData\ssh\sshd_config.backup C:\ProgramData\ssh\sshd_config -Force
Restart-Service sshd
Troubleshooting and rollback
OpenSSH Server will not install
IfAdd-WindowsCapability returns errors such as 0x800F0954, 0x800F0950, or Windows Update-related errors, the PC may be offline or governed by WSUS, another intranet update service, or a policy that blocks optional-feature downloads.First, confirm the feature state:
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'If the server remains
NotPresent, ask the organization’s Windows-update administrator to permit Features on Demand downloads or provide a Features on Demand source matching the exact Windows version and build. Do not install an arbitrary third-party OpenSSH package as a substitute for the built-in feature without a patching and ownership plan.Start-Service sshd reports that the service does not exist
The server capability is not installed, or installation did not finish. Re-run:Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0Then restart Windows if the installation reports that it is required, and repeat:
Code:
Start-Service sshd
Set-Service sshd -StartupType Automatic
Connection is refused or immediately reset
On the server, verify the service and firewall rule:
Code:
Get-Service sshd
Get-NetFirewallRule -Name OpenSSH-Server-In-TCP
Get-NetTCPConnection -LocalPort 22 -State Listen
sshdisRunning.- The firewall rule exists and is enabled.
- A listener exists on TCP port 22.
Code:
Get-NetTCPConnection -LocalPort 22 -State Listen |
Select-Object LocalAddress, LocalPort, OwningProcess
Get-Process -Id <OwningProcess>
From the client, test network reachability:
Test-NetConnection 192.168.50.25 -Port 22TcpTestSucceeded : True confirms that the client can reach the SSH service. If it is False, check the server firewall rule, the selected network profile, VPN rules, guest Wi-Fi isolation, and the IP address.The password is rejected
Confirm that the username format matches the account type:
Code:
ssh [email][email protected][/email]
ssh domain\[email][email protected][/email]
sshd_config file from a local console.Public-key authentication returns Permission denied (publickey)
Use verbose client output to see whether the correct key is offered:ssh -vvv -i $env:USERPROFILE\.ssh\id_ed25519 [email][email protected][/email]Check these common causes:
- The public key in
authorized_keysis incomplete, wrapped onto multiple lines, or copied from the wrong client key. - A standard user’s public key is not in
C:\Users\username\.ssh\authorized_keys. - An administrator’s public key is incorrectly stored in the user profile instead of
C:\ProgramData\ssh\administrators_authorized_keys. - The administrator key file permissions were changed.
Code:
icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" `
/inheritance:r `
/grant "Administrators:F" `
/grant "SYSTEM:F"
Restart-Service sshdRemove or fully disable OpenSSH Server
To immediately stop remote SSH access while retaining the installed feature:
Code:
Stop-Service sshd
Set-Service -Name sshd -StartupType Disabled
Disable-NetFirewallRule -Name OpenSSH-Server-In-TCP
Code:
Set-Service -Name sshd -StartupType Automatic
Enable-NetFirewallRule -Name OpenSSH-Server-In-TCP
Start-Service sshd
Code:
Stop-Service sshd -ErrorAction SilentlyContinue
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Remove-NetFirewallRule -Name OpenSSH-Server-In-TCP -ErrorAction SilentlyContinue