Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Can't SSH Into VPS? Troubleshooting Steps That Work

· 6 min read · Home Tech

In this article
  1. Start With the Basics: Is the Server Even Reachable?
  2. Use the Provider's Web Console (Out-of-Band Access)
  3. Check if the SSH Service Is Running and Listening
  4. Examine Firewall Rules (ufw, firewalld, iptables)
  5. Check for IP Bans (fail2ban, DenyHosts, etc.)
  6. Verify Authentication Method: Keys vs. Password
  7. Common Misconceptions and Extra Tips
  8. Frequently Asked Questions

If you can't SSH into your VPS, the fix is usually one of a few common issues: the SSH service isn't running, the firewall is blocking port 22, your IP is banned, or your key/credentials are wrong. This article walks through the most effective troubleshooting steps in order, from quick checks to deeper fixes.

Start With the Basics: Is the Server Even Reachable?

Before diving into SSH-specific settings, confirm the server itself is online and reachable over the network. A quick ping test (ICMP) can tell you if the machine is up, though some providers block ping by default. If ping fails, it doesn't necessarily mean the server is down—it could be a firewall rule. The more reliable test is to check if any TCP port is open.

  • Ping the server: ping your-server-ip – if you get replies, the network path is working.
  • Check port 22 with a tool like nc or telnet: nc -zv your-server-ip 22 – if it says "succeeded" or "open", the port is reachable.
  • Try connecting from a different network (e.g., mobile hotspot) to rule out local ISP or firewall blocks.

If the port is not reachable, the issue is likely at the server or network level—proceed to the next steps.

Use the Provider's Web Console (Out-of-Band Access)

Most VPS providers offer a web-based console (often called VNC, noVNC, or "Console") that gives you direct access to the server's screen, even if SSH is down. This is your lifeline. Log in to your provider's control panel, find your VPS, and open the console. From there, you can log in with your root or user credentials and run diagnostics locally.

If you don't have the root password (because you use SSH keys only), you may need to reset it via the provider's panel. Many providers allow you to set a temporary root password or mount a recovery ISO. This console access is essential for the next steps.

Check if the SSH Service Is Running and Listening

Once you're in the console, verify that the SSH daemon (sshd) is actually running and listening on the expected port.

  1. Check the service status: systemctl status sshd (or service ssh status on older systems). If it's not running, start it: systemctl start sshd.
  2. Check if it's listening: ss -tlnp | grep ssh or netstat -tlnp | grep ssh. You should see a line like 0.0.0.0:22 or [::]:22. If it's only listening on a specific IP (e.g., 127.0.0.1), that's why you can't connect from outside.
  3. Check the SSH config: Look at /etc/ssh/sshd_config for lines like Port 22, ListenAddress, and PermitRootLogin. If you changed the port, you need to connect to that port (e.g., ssh -p 2222 user@ip).

If sshd isn't installed at all, install it with your package manager (e.g., apt install openssh-server on Debian/Ubuntu).

Examine Firewall Rules (ufw, firewalld, iptables)

Firewalls are the most common reason for SSH being unreachable. Check if a firewall is active and whether it allows SSH traffic.

  • UFW (Ubuntu/Debian): sudo ufw status – if it shows "active", make sure port 22 (or your custom port) is allowed: sudo ufw allow 22/tcp.
  • firewalld (CentOS/RHEL/Fedora): sudo firewall-cmd --list-all – if ssh is not listed, add it: sudo firewall-cmd --add-service=ssh --permanent and reload.
  • iptables (raw): sudo iptables -L -n – look for rules that drop or reject port 22. Be careful: if you're not sure, you can temporarily flush rules with sudo iptables -F (but this will also remove other rules, so use with caution).

Also check the provider's cloud firewall or security group settings in their control panel. Some providers have a separate firewall layer (e.g., AWS Security Groups, DigitalOcean Cloud Firewall) that must explicitly allow inbound TCP on port 22.

Check for IP Bans (fail2ban, DenyHosts, etc.)

If you've had multiple failed login attempts, tools like fail2ban may have banned your IP. Check if fail2ban is installed and active:

sudo fail2ban-client status sshd

If you see your IP in the banned list, unban it with:

sudo fail2ban-client set sshd unbanip YOUR_IP

Also check /etc/hosts.deny and /etc/hosts.allow (TCP wrappers) for any deny entries. And look at the SSH logs (/var/log/auth.log or /var/log/secure) to see if your connection attempts are being rejected and why.

Verify Authentication Method: Keys vs. Password

If the server is reachable but you're getting "Permission denied", the problem is authentication. Common issues:

  • Wrong username: Make sure you're using the correct user (often root or a user you created). If you're unsure, check the provider's default credentials.
  • SSH key not accepted: If you use key-based auth, ensure your public key is in ~/.ssh/authorized_keys on the server, and that the file permissions are correct (should be 600 for the file and 700 for the .ssh directory). If you're using a key that's not registered, you'll be denied.
  • Password auth disabled: If PasswordAuthentication no is set in sshd_config, you can't log in with a password. You'll need to use a key, or temporarily re-enable password auth via the console.
  • Root login disabled: If PermitRootLogin no, you can't SSH as root. Log in as a regular user and then su or use sudo.

If you have console access, you can always reset the password or add your public key manually to authorized_keys.

Common Misconceptions and Extra Tips

One misconception is that if you can ping the server, SSH should work. That's false—ping uses ICMP, which is a different protocol and may be allowed while TCP port 22 is blocked. Another is that changing the SSH port improves security significantly; it can reduce automated scans, but it's not a substitute for key-based auth and a firewall.

If you recently changed your VPS provider or migrated, double-check that the new server's IP is correct and that there's no leftover SSH config pointing to the old one (check ~/.ssh/known_hosts for mismatched keys). If you get a "REMOTE HOST IDENTIFICATION HAS CHANGED" warning, it means the server's key changed (e.g., after a reinstall); you can remove the old key with ssh-keygen -R your-server-ip.

Finally, if you're still stuck, consider booting into rescue mode (most providers offer this) to inspect the filesystem and fix config files directly. This is especially useful if you've locked yourself out by editing sshd_config incorrectly.

Frequently Asked Questions

Why do I get "Connection timed out" when trying to SSH?

A timeout usually means the server is not responding on port 22—either the SSH service is down, a firewall is dropping packets, or the server is offline. Check the provider's console to see if the server is running, and verify the firewall rules.

What should I do if I forgot my SSH password?

Use the provider's web console to log in (if you have root access) and reset the password with passwd. If you don't have console access, you may need to use the provider's password reset feature or reinstall the OS.

Can I SSH into my VPS using a different port?

Yes. Edit /etc/ssh/sshd_config and change the Port line to a custom port (e.g., 2222), then restart sshd. Remember to update your firewall rules and connect with ssh -p 2222 user@ip.

Why does my SSH connection drop after a few minutes of inactivity?

This is often due to a timeout setting in the SSH client or server. You can keep the connection alive by adding ServerAliveInterval 60 to your client's ~/.ssh/config, or set ClientAliveInterval in the server's sshd_config.

What if I see "Permission denied (publickey)" even though I'm using the right key?

Check that your public key is correctly placed in ~/.ssh/authorized_keys on the server, and that the file and directory permissions are correct. Also verify that you're using the correct private key file and that the key type is supported by the server (e.g., RSA, Ed25519).

Is it safe to disable password authentication and use only keys?

Yes, it's generally more secure, as it prevents brute-force password attacks. However, ensure you have a backup access method (like the web console) in case you lose your key.