Table of Contents
- Table of Contents
- Enable SSH Access from Linux to Windows (Port 22)
Enable SSH Access from Linux to Windows (Port 22)
This guide explains how to enable a Windows machine to accept SSH connections on port 22 from a Linux machine using OpenSSH Server.
1. Install OpenSSH Server on Windows
Option A: Windows 10 / 11 (GUI)
- Open Settings
- Navigate to Apps → Optional Features
- Click Add a feature
- Install:
- OpenSSH Server
- (Optional) OpenSSH Client
Option B: PowerShell (Run as Administrator)
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
2. Start and Enable the SSH Service
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
Verify:
Get-Service sshd
3. Allow Port 22 Through Windows Firewall
Windows usually adds this rule automatically, but verify it exists.
Get-NetFirewallRule -Name *ssh*
If missing, create it:
New-NetFirewallRule `
-Name "OpenSSH-Server-In-TCP" `
-DisplayName "OpenSSH Server (SSH)" `
-Enabled True `
-Direction Inbound `
-Protocol TCP `
-Action Allow `
-LocalPort 22
4. Verify SSH Is Listening on Port 22
netstat -ano | findstr :22
Expected output:
TCP 0.0.0.0:22 LISTENING
5. Connect from Linux
From the Linux machine:
ssh windows_username@windows_ip
Example:
ssh ryan@192.168.1.50
Explicit port (optional):
ssh -p 22 ryan@192.168.1.50
6. Authentication Details
- SSH uses Windows user credentials
- Valid username formats:
usernameCOMPUTERNAME\username
If one fails, try the other.
7. (Optional) Enable SSH Key Authentication
Generate a Key on Linux
ssh-keygen
Copy the Key to Windows
ssh-copy-id ryan@windows_ip
Or manually place the public key in:
C:\Users\ryan\.ssh\authorized_keys
Fix Permissions on Windows (Required)
icacls $env:USERPROFILE\.ssh /inheritance:r
icacls $env:USERPROFILE\.ssh /grant "$env:USERNAME:(F)"
Restart SSH:
Restart-Service sshd
8. Common Problems and Fixes
Connection Refused
sshdservice not running- Firewall blocking port 22
Permission Denied
- Incorrect username format
- Password authentication disabled
Check configuration:
C:\ProgramData\ssh\sshd_config
Ensure:
PasswordAuthentication yes
PubkeyAuthentication yes
Restart service after changes:
Restart-Service sshd
9. Debug from Linux
ssh -vvv ryan@windows_ip
This provides verbose output showing authentication and connection failures.
Notes
- Port forwarding is required for WAN access
- Consider key-only authentication for security
- You can change the SSH port in
sshd_configif needed