Table of Contents

  1. Table of Contents
  2. Enable SSH Access from Linux to Windows (Port 22)
    1. 1. Install OpenSSH Server on Windows
      1. Option A: Windows 10 / 11 (GUI)
      2. Option B: PowerShell (Run as Administrator)
    2. 2. Start and Enable the SSH Service
    3. 3. Allow Port 22 Through Windows Firewall
    4. 4. Verify SSH Is Listening on Port 22
    5. 5. Connect from Linux
    6. 6. Authentication Details
    7. 7. (Optional) Enable SSH Key Authentication
      1. Generate a Key on Linux
      2. Copy the Key to Windows
      3. Fix Permissions on Windows (Required)
    8. 8. Common Problems and Fixes
      1. Connection Refused
      2. Permission Denied
    9. 9. Debug from Linux
    10. Notes

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)

  1. Open Settings
  2. Navigate to Apps → Optional Features
  3. Click Add a feature
  4. 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:
    • username
    • COMPUTERNAME\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

  • sshd service 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_config if needed