Advertisement
efxtv

How to Enable SSH on Windows 10/11 and Fix "Connection Refused" Errors

Jun 19th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | Cryptocurrency | 0 0
  1. # How to Enable SSH on Windows 10/11 and Fix "Connection Refused" Errors
  2.  
  3. ## Install OpenSSH Server
  4. 1. Open Settings ($Win + I)
  5. 2. Go to Apps > Optional Features
  6. 3. Click "Add a feature"
  7. 4. Search for "OpenSSH Server" and install it
  8.  
  9. ## Start SSH Service
  10. $ Get-Service -Name sshd | Start-Service
  11. OR
  12. 1. Open Services ($Win + R, type services.msc)
  13. 2. Find "OpenSSH SSH Server"
  14. 3. Right-click and select "Start"
  15. 4. (Optional) Set Startup Type to "Automatic"
  16.  
  17. ## Configure Firewall
  18. 1. Open Windows Defender Firewall
  19. 2. Click "Allow an app through firewall"
  20. 3. Ensure "OpenSSH Server" is checked for both Private/Public
  21. OR
  22. $ netsh advfirewall firewall add rule name="OpenSSH Server" dir=in action=allow protocol=TCP localport=22
  23.  
  24. ## Verify Installation
  25. $ ssh localhost
  26. $ netstat -ano | findstr :22
  27.  
  28. ## Troubleshooting "Connection Refused"
  29.  
  30. ### If service won't start:
  31. 1. Check configuration file:
  32. $ notepad C:\ProgramData\ssh\sshd_config
  33. 2. Ensure line exists: Port 22 (no #)
  34.  
  35. ### Reinstall if needed:
  36. $ Stop-Service sshd
  37. $ Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
  38. $ Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  39. $ Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  40.  
  41. ### Check logs:
  42. $ Get-EventLog -LogName Application -Source OpenSSH -Newest 10
  43.  
  44. ## Alternative Methods
  45. 1. Using PowerShell:
  46. $ Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  47.  
  48. 2. Via Windows Features:
  49. $ Enable-WindowsOptionalFeature -Online -FeatureName OpenSSH.Server
  50.  
  51. ## Final Checks
  52. $ Test-NetConnection -ComputerName localhost -Port 22
  53. $ systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement