[Windows] Enable Windows default SSH server

This topic is already well documented by mircosoft docs. You can find it from Get started with OpenSSH.

Here I just want to give two tips for accelerating the setup.

  1. There are two ways to activate the open ssh server on Windows: from Windows Settings or PowerShell. Personally, I would recommend to use the PowerShell. Open the PowerShell as an Administrator.
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

# Install server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# Start the sshd service
Start-Service sshd

# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

# 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 | 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."
}
  1. When you try to connect the OpenSSH server, you’ll need to use ssh username@servername.
    The servername is your device’s IP address. For example, 192.168.1.5.
    The username may confuse you. But you can find it by typing whoami in PowerShell or Command. It may look like laptop-nbgksu9c\user.

In the ~/.ssh/config file, you can configure it like

Host windowsdevice
	HostName 192.168.1.5
	User laptop-nbgksu9c\user
	Port 22

Then you can simply type ssh windowsdevice from where you want to connect the Windows device. The work will be done.


If this post helped you to solve a problem or provided you with new insights, please upvote it and share your experience in the comments below. Your comments can help others who may be facing similar challenges. Thank you!
Buy Me A Coffee
DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !