Verify SSH Service Availability
Before adjusting network settings, confirm that the SSH daemon is actually running on the Windows machine. Modern versions of Windows 10 and 11 include OpenSSH Server as an optional feature. If this feature is not installed or has stopped running, no amount of firewall tweaking will resolve the timeout.
Open PowerShell as an Administrator on the Windows machine and execute the following command to check the service status:
Get-Service -Name sshd
If the Status column shows Running, the service is active. If it shows Stopped, start it immediately using:
Start-Service sshd
To ensure the service starts automatically after reboots, change its startup type to automatic:
Set-Service -Name sshd -StartupType 'Automatic'
If the service is not listed at all, you must install the OpenSSH Server feature via Settings > Apps > Optional Features, or by running Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 in PowerShell.
Configure Windows Defender Firewall
The most common cause for a "Connection timed out" error is the Windows Defender Firewall blocking incoming traffic on port 22 (the default SSH port). Even if the service is running, the firewall may drop packets before they reach the application.
You need to create an inbound rule to allow TCP traffic on port 22. In PowerShell (Admin), run:
New-NetFirewallRule -DisplayName "Allow SSH" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow
This command explicitly permits incoming connections on the standard SSH port. After executing this, test the connection from your Ubuntu machine again. If the timeout persists, verify that your Windows machine is on the same subnet as the Ubuntu system, or that no intermediate hardware firewalls are interfering.
Check Network Connectivity and Routing
Ensure that the Ubuntu machine can physically reach the Windows IP address. Use the ping command from Ubuntu to check basic connectivity:
ping <Windows_IP_Address>
If ping fails, the issue is likely a network configuration problem rather than an SSH-specific one. Check your network adapter settings on both machines. If you are working within a virtualized environment, such as Hyper-V or VMware, ensure that the virtual network adapter is set to bridged mode or properly NATted so that the Ubuntu VM can see the host or other VMs on the local network.
For those encountering similar issues with WSL (Windows Subsystem for Linux) networking, you might find relevant details in our article on Troubleshooting SSH WSL Machine: Can't Connect to Localhost.
Configure Port Forwarding for Remote Access
If you are attempting to connect to the Windows machine from outside your local network (e.g., over the internet), you must configure port forwarding on your router. The router needs to direct incoming traffic on a specific external port to the internal IP address of your Windows machine on port 22.
- Log into your router's admin interface.
- Navigate to the Port Forwarding or Virtual Server section.
- Create a new rule: External Port 22 (or a non-standard high port for security), Internal Port 22, Protocol TCP, and the internal IP of your Windows PC.
After saving the router settings, use your public IP address or dynamic DNS hostname to connect from Ubuntu:
ssh username@your_public_ip
Note that many ISPs block incoming port 22 traffic by default. If you cannot connect, try mapping an external port like 2222 to internal port 22, and connect using ssh -p 2222 username@public_ip.
Debugging Connection Issues
If the connection still times out, use verbose mode on the Ubuntu client to see exactly where the handshake fails. Run:
ssh -v username@windows_ip
Look for lines indicating "Connection refused" versus "Connection timed out." A refusal means the server is reachable but rejecting the connection (often a firewall or service issue), while a timeout means the packets are disappearing somewhere in the network path. For more complex reset issues when moving between different OS environments, refer to SSH to Linux from Windows 11: Troubleshooting Connection Reset Issues.
Frequently Asked Questions
Why does SSH work locally but fail remotely?
This typically happens because your router does not have port forwarding configured for the SSH port, or your ISP is blocking inbound traffic on port 22. You must map an external port on your router to the internal IP of your Windows machine.
Can I use a different port for SSH to avoid firewall issues?
Yes, you can change the listening port of the OpenSSH server in Windows by editing the sshd_config file located in C:\ProgramData\ssh\. Remember to update your firewall rules and router port forwarding to match the new port number.
What if I get "Connection Refused" instead of a timeout?
A connection refused error means the network path is clear, but the destination actively rejected the connection. This usually indicates that the SSH service is not running on the Windows machine, or the firewall is explicitly dropping the packet rather than silently discarding it.
How do I check if my Windows firewall is allowing SSH?
You can list all inbound firewall rules in PowerShell by running Get-NetFirewallRule | Where-Object {$_.DisplayName -like "*SSH*"}. Ensure the Enabled property is True and the Action is Allow.
Is it safe to expose SSH directly to the internet?
Exposing SSH directly is risky due to brute-force attacks. It is safer to use a VPN, change the default port to something obscure, or use key-based authentication exclusively to prevent password guessing attempts.