Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # How to Enable SSH on Windows 10/11 and Fix "Connection Refused" Errors
- ## Install OpenSSH Server
- 1. Open Settings ($Win + I)
- 2. Go to Apps > Optional Features
- 3. Click "Add a feature"
- 4. Search for "OpenSSH Server" and install it
- ## Start SSH Service
- $ Get-Service -Name sshd | Start-Service
- OR
- 1. Open Services ($Win + R, type services.msc)
- 2. Find "OpenSSH SSH Server"
- 3. Right-click and select "Start"
- 4. (Optional) Set Startup Type to "Automatic"
- ## Configure Firewall
- 1. Open Windows Defender Firewall
- 2. Click "Allow an app through firewall"
- 3. Ensure "OpenSSH Server" is checked for both Private/Public
- OR
- $ netsh advfirewall firewall add rule name="OpenSSH Server" dir=in action=allow protocol=TCP localport=22
- ## Verify Installation
- $ ssh localhost
- $ netstat -ano | findstr :22
- ## Troubleshooting "Connection Refused"
- ### If service won't start:
- 1. Check configuration file:
- $ notepad C:\ProgramData\ssh\sshd_config
- 2. Ensure line exists: Port 22 (no #)
- ### Reinstall if needed:
- $ Stop-Service sshd
- $ Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
- $ Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
- $ Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
- ### Check logs:
- $ Get-EventLog -LogName Application -Source OpenSSH -Newest 10
- ## Alternative Methods
- 1. Using PowerShell:
- $ Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
- 2. Via Windows Features:
- $ Enable-WindowsOptionalFeature -Online -FeatureName OpenSSH.Server
- ## Final Checks
- $ Test-NetConnection -ComputerName localhost -Port 22
- $ systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement