Management Guides Troubleshooting

VPS SSH "Connection Timed Out": Causes and Fixes

What "connection timed out", "connection refused" and "permission denied" each mean when SSH to a VPS fails, how to get in through the web console, and how to fix firewall, fail2ban and sshd problems.

The exact error SSH prints tells you where the problem is. "Connection timed out" means nothing answered: a firewall dropped the packets, the server is down, or the address is wrong. "Connection refused" means the server answered and nothing is listening on that port. "Permission denied" means you reached SSH and your login was rejected. This guide deals with each, starting with the timeout.

Read the error first

MessageWhat it meansWhere to look
Connection timed outNo reply at allFirewall, banned IP, server down, wrong IP, network path
Connection refusedHost reachable, port closedsshd not running, or listening on another port
Permission denied (publickey)SSH reached, key not acceptedWrong user, wrong key, file permissions
No route to hostNetwork cannot reach the addressServer off, IP changed, provider network
Host key verification failedThe server's identity changedRebuilt server, or something in between
Session freezes after workingIdle connection droppedKeep-alive settings

Checks from your own computer

1. Is it the right address and port? Confirm the IP in the provider's panel. A rebuilt or restored server may have a new one.

2. Does the port answer?

nc -vz YOUR_SERVER_IP 22
# Windows PowerShell
Test-NetConnection YOUR_SERVER_IP -Port 22

3. Is it only you? Try from another network, such as a phone hotspot. If that works, your own IP address is blocked on the server (see fail2ban below) or your network blocks outgoing port 22.

4. IPv4 or IPv6? If the hostname has both kinds of address and only one is allowed through the firewall, force one: ssh -4 user@host or ssh -6 user@host.

5. Ask SSH what it is doing:

ssh -vvv user@YOUR_SERVER_IP

If the output stops at "Connecting to ... port 22", nothing is answering. If it gets as far as offering keys, the network is fine and the problem is authentication.

Get in another way: the web console

Every VPS provider offers a console in its control panel (called VNC, web console, serial console or similar). It gives you a login on the server's screen without using SSH or the network firewall. Log in there with a user that has a password. If you never set a password, most panels can reset the root password or boot the server into a rescue system.

While you are in the panel, check that the server is running and whether the provider reports an incident for its location.

Checks on the server (through the console)

Is SSH running and on which port?

sudo systemctl status ssh        # sshd on AlmaLinux, Rocky Linux
sudo ss -tlnp | grep -i ssh

If the service failed, sudo sshd -t prints the configuration error that stopped it, usually a typo from the last edit. On recent Ubuntu releases SSH is started by a socket unit; if the status shows the service inactive, also check sudo systemctl status ssh.socket.

Is the firewall blocking it?

sudo ufw status verbose                 # Ubuntu, Debian
sudo firewall-cmd --list-all            # AlmaLinux, Rocky Linux

The most common cause of a sudden timeout is enabling ufw without allowing SSH, or changing the SSH port without opening the new one. Fix:

sudo ufw allow OpenSSH                  # or: sudo ufw allow 2222/tcp
sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload

Check the provider's cloud firewall or security group as well. It sits in front of the server and is configured in the panel, not on the machine.

Did fail2ban ban you? A few mistyped passwords are enough.

sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip YOUR_IP

To avoid a repeat, add your address to ignoreip in /etc/fail2ban/jail.local if it is static.

Is the server healthy? A full disk or exhausted memory can stop new logins.

df -h
free -h
sudo journalctl -u ssh -n 50 --no-pager

See "No space left on device" and the OOM killer guide if either turns out to be the cause.

Does the server have a network?

ip addr
ip route
ping -c 3 1.1.1.1

If there is no address or no default route, a network configuration change or a failed update broke it; the provider's documentation has the correct settings for your plan.

Connection refused

The machine is reachable and nothing accepts connections on that port. Either sshd is stopped (start it and read sudo sshd -t), or it listens on a different port. Check Port in /etc/ssh/sshd_config and the files in /etc/ssh/sshd_config.d/, then connect with ssh -p PORT user@host.

Permission denied (publickey)

  • Wrong user. The key is installed for one account; root, ubuntu and your own user are different.
  • Wrong key. Name it explicitly: ssh -i ~/.ssh/id_ed25519 user@host.
  • Permissions on the server. SSH ignores keys in files that others can write to:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    chown -R $USER:$USER ~/.ssh
  • The account is not allowed. An AllowUsers line in the SSH configuration that does not include your user refuses it whatever the key.

The server's side of the story is in sudo journalctl -u ssh -n 30, which usually states the reason plainly.

Host key verification failed

Your computer remembers each server's key and warns when it changes. If you have just rebuilt or reinstalled the server, that is expected; remove the old entry and connect again:

ssh-keygen -R YOUR_SERVER_IP

If you did not change anything, stop and find out why before accepting the new key. Compare the fingerprint with the one shown in the provider's console.

Sessions that freeze when idle

Routers and firewalls between you and the server drop connections that are silent for a while. Tell your SSH client to send a small keep-alive. In ~/.ssh/config on your computer:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

For long-running jobs, start them inside tmux or screen so that a dropped connection does not kill them.

How to avoid locking yourself out

  • Keep an existing session open while you change SSH or firewall settings, and test from a second terminal.
  • Run sudo sshd -t before every reload.
  • Allow the SSH port in the firewall before enabling the firewall or changing the port.
  • Know where the provider's web console is before you need it, and set a password for one sudo user so that you can log in there.

The initial server setup guide and the hardening checklist follow these rules step by step.

Frequently asked questions

Why did SSH stop working after I enabled the firewall?

The firewall's default is to refuse incoming connections, and SSH was not on the allow list. Add it through the web console as shown above.

Can my internet provider block SSH?

Some company, hotel and mobile networks block outgoing port 22. Testing from another network shows this quickly.

The server responds to ping but SSH times out. Why?

The machine is up and a firewall rule, a ban or a stopped SSH service is the cause. Ping uses a different protocol and says nothing about port 22.

Can I recover a server if I lost my SSH key?

Yes: log in through the web console or the rescue system and add a new public key to ~/.ssh/authorized_keys.

Share story:

Continue reading other guides on How VPS.