Introduction
You type ssh user@your-server, the cursor hangs on "connecting", and then it times out. Worse, the machine seems alive: the site it hosts still loads fine. An SSH timeout means the network or the service refused your connection somewhere along the path, and the cause is almost always one of a short list. This guide walks through a layered check that narrows down the scope in minutes, then fixes each cause.

Narrow Down the Scope First
Do not start by changing things. Start by finding out which layer is broken.
Layer 1: Is the machine reachable?
ping your-server-ipIf ping fails entirely, the problem is network-level: the machine is down, the IP changed, or traffic is blocked before it reaches the host. If ping works, the machine is alive and the problem is narrower.
Layer 2: Is port 22 open?
nc -zv your-server-ip 22A "succeeded" here means the port accepts connections, so the problem is likely in SSH itself (authentication, config, or your client). A timeout here means something is dropping packets before sshd: a firewall, a security group, or a changed port.
Layer 3: Is sshd actually running?
If you can reach the machine through your provider's web console (VNC), log in there and check:
systemctl status ssh
ss -tlnp | grep :22
journalctl -u ssh -n 50The status shows whether the daemon is up, the ss line shows what port it actually listens on, and the journal shows its recent complaints, including refused and dropped connections.
With these three layers you already know where to dig.
Cause 1: Firewall or Security Group
The single most common cause. Two doors have to be open at the same time:
The provider's security group or firewall panel. Many providers ship VPS with only a few ports allowed by default. If port 22 (or your custom SSH port) is not in the allow list, every connection dies silently at the edge.
The OS-level firewall.
ufw,firewalld, or rawnftablesrules on the machine itself. A common trap: enabling ufw on a fresh machine without allowing SSH first, which locks you out in one command.
The fix is symmetric: allow the SSH port in both places. If you locked yourself out with the OS firewall, use the web console to get in and run ufw allow 22/tcp (or your custom port).
One habit from my own workflow: before touching firewall rules on my VMRack VPS, I take a snapshot first, so a locked-out machine is one rollback away instead of a rebuild.
Cause 2: sshd Is Down or Misconfigured
If the port is reachable but the service misbehaves, check the config before reinstalling anything:
sshd -tThis validates the sshd config and prints the exact line that is broken, and it is the command to run after every edit of sshd_config. Typical self-inflicted wounds include a typo in the config that stops the daemon from starting, a ListenAddress pointing to an address the machine no longer has, or a restart that never happened after a port change.
Fix the reported line, then restart and verify:
sudo systemctl restart ssh
sudo systemctl status sshCause 3: The Port Changed
If you (or a hardening script) changed the Port directive in sshd_config, your old ssh user@ip command is knocking on the wrong door. Connect with the new port explicitly:
ssh -p 2222 user@your-server-ipAnd remember the firewall has to allow the new port too; changing the port without opening it is a classic self-lockout.
Cause 4: The Server Is Overloaded
sshd needs CPU and memory to accept your login. A machine pinned at 100% CPU or gasping for memory can time out SSH while the site it hosts still limps along. If the web console works but SSH crawls, check load and memory there first. For the memory side of this problem, the article "OOM Killer on a VPS: Why Processes Die and How Swap Helps" on this site covers how to read the signals and relieve the pressure.
Cause 5: You Banned Yourself
If you run fail2ban or similar brute-force protection, repeated failed logins from your own IP (a wrong key, an old password manager entry) can get you banned. The symptom is precise: SSH worked a minute ago, nothing changed on the server, and now every attempt times out.
Through the web console, check and unban:
sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip your-ipThen fix the credential that caused the failures, or the ban will simply come back.
Cause 6: The Path Is Blocked Elsewhere
Some corporate networks, hotels, and ISPs block port 22 or all non-web ports. If the server side checks out completely, test from a different network: your phone's hotspot is the fastest control experiment. If SSH works over hotspot but not over the office network, the server was never the problem.
Prevention
Four habits make SSH lockouts rare and recoverable:
Keep an out-of-band door. Know where your provider's web console is and confirm you can log in to it before you need it.
Snapshot before risky edits. Firewall changes and sshd config edits are the two classic lockout triggers.
Validate configs. Run
sshd -tafter every config change, and keep the session open while testing from a second terminal.Add keepalive settings on the client side to distinguish an idle disconnect from a real timeout:
ServerAliveInterval 60in your local ssh config.
Conclusion
An SSH timeout is a routing problem with a short list of suspects. Walk the layers in order: ping for reachability, nc for the port, the web console for the service. Then match the fix to the cause: open the port in both firewalls, repair the config line that sshd -t reports, knock on the right port, relieve an overloaded machine, unban your own IP, or switch networks to prove the path. Keep a snapshot before risky edits and an out-of-band console within reach, and a timeout becomes a five-minute chore instead of a lost evening.
Thank you for reading to the end!