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.
- There are two ways to activate the open ssh server on Windows: from
Windows Settings
orPowerShell
. Personally, I would recommend to use thePowerShell
. 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."
}
- When you try to connect the OpenSSH server, you’ll need to use
ssh username@servername
.
Theservername
is your device’s IP address. For example,192.168.1.5
.
Theusername
may confuse you. But you can find it by typingwhoami
in PowerShell or Command. It may look likelaptop-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!