To fix SSH connection timed out on port 22 on a Linux VPS: Execute ssh -vvv user@server_ip to verify packet drop points, log in through your hosting provider's out-of-band VNC console, unban your IP using fail2ban-client set sshd unbanip <your_ip>, allow inbound traffic via ufw allow 22/tcp or firewall-cmd --permanent --add-service=ssh, and verify cloud provider security group ingress rules permit TCP 22.[1][2]
Follow this step-by-step systems administration runbook to trace TCP SYN packet drops, recover locked remote sessions, and configure resilient firewall perimeters across Ubuntu, Debian, AlmaLinux, and Rocky Linux cloud servers.[1][3]
Why Does a Linux VPS Throw SSH Connection Timed Out on Port 22?
The terminal error ssh: connect to host <IP_ADDRESS> port 22: Connection timed out indicates a complete TCP handshake failure (OSI Layer 4).[1] Unlike a “Connection refused” error—where the remote host receives your packet and explicitly replies with a TCP Reset (RST) because no daemon is listening—a “Connection timed out” error means your initial TCP SYN packet disappeared into a black hole with zero acknowledgment.[1][2]
This packet loss typically stems from four distinct architectural barriers:
- Host-Level Firewall Drops: The internal Linux firewall (UFW, Firewalld, or
nftables/iptables) is configured to drop unauthenticated packets silently rather than rejecting them, blocking inbound connections on port 22.[1][4] - Automated Fail2ban Jails: If you entered an incorrect SSH key passphrase, repeatedly typed a bad password, or a background SFTP script failed multiple authentication attempts, Fail2ban dynamically injected an
iptablesornftablesDROPrule targeting your client’s public IP.[2] - Hypervisor Security Group & Edge VPC Firewalls: Cloud platforms enforce external software-defined networking (SDN) firewalls outside the operating system. If the ingress security group lacks an explicit rule permitting TCP port 22, the cloud gateway discards packets before they reach the virtual network interface card (vNIC).[1]
- Local ISP or Corporate Network Filtering: Certain enterprise offices, public Wi-Fi networks, and mobile carriers block outbound connections on non-standard or standard administrative ports (including port 22) to prevent unauthorized tunneling.[3]
Diagnostic Matrix: SSH Connection Failure Signatures
| Terminal Error Output | Failure Mechanism | OSI Layer | Immediate Root Cause |
|---|---|---|---|
Connection timed out |
Silent packet drop | Transport (Layer 4) | Inbound firewall DROP, Fail2ban jail, or cloud security group |
Connection refused |
TCP RST received |
Transport / Service | sshd daemon is stopped or listening on a custom port |
Permission denied (publickey) |
Handshake succeeded | Application (Layer 7) | Incorrect SSH private key, bad permissions on ~/.ssh/authorized_keys |
No route to host |
ICMP host unreachable | Network (Layer 3) | Subnet routing failure, server offline, or IP misconfiguration |
Host key verification failed |
Man-in-the-middle check | Application (Layer 7) | Remote server reinstalled; stale entry in local ~/.ssh/known_hosts |
Diagnostic Checklist: How to Fix SSH Connection Timed Out on Linux VPS
Execute this sequential diagnostic protocol to identify where packets are being discarded and regain administrative access.
Step 1: Run Verbose Client-Side Diagnostics
Execute your connection with triple-verbosity enabled to inspect the exact socket state where execution stalls:
# Run verbose SSH from your local workstation terminal
ssh -vvv [email protected]
Analyze the terminal output:
OpenSSH_9.6p1, LibreSSL 3.3.6
debug1: Connecting to 192.0.2.100 [192.0.2.100] port 22.
debug1: connect to address 192.0.2.100 port 22: Connection timed out
ssh: connect to host 192.0.2.100 port 22: Connection timed out
If execution halts immediately after Connecting to..., no TCP SYN-ACK was returned. Test raw port transit via Netcat or PowerShell:
# From Linux / macOS:
nc -zv -w 5 192.0.2.100 22
# From Windows PowerShell:
Test-NetConnection -ComputerName 192.0.2.100 -Port 22
Step 2: Access the VPS via Out-of-Band Web Console (VNC / KVM)
Because SSH is inaccessible over the network, you must establish an out-of-band administrative connection. Log into your hosting control panel—such as the management portal for Nextgen Hosting Dedicated Servers or Pakistan Dedicated Servers—and launch the VNC / KVM Web Console.[1]
Once logged in directly through the virtual terminal, execute the following remediation commands.
Unbanning Client IPs from Fail2ban and IPTables Drops
Fail2ban monitors /var/log/auth.log or systemd journals. Upon detecting multiple failed login events, it inserts an instant DROP rule for the offending IP address.[2]
Step 1: Inspect Fail2ban Jail Status
# Query the status of the SSH jail
sudo fail2ban-client status sshd
# Sample output:
# Status for the jail: sshd
# |- Filter
# | |- Currently failed: 2
# | `- Total failed: 48
# `- Actions
# |- Currently banned: 1
# `- Banned IP list: 203.0.113.45
Step 2: Unban Your Public IP Address
Find your local public IP address (visit ifconfig.me on your workstation) and remove it from the active jail:
# Unban specific client IP from Fail2ban
sudo fail2ban-client set sshd unbanip 203.0.113.45
Step 3: Whitelist Your Static Management IP
To permanently prevent accidental lockouts, add your management IP to /etc/fail2ban/jail.local:
[DEFAULT]
# Whitelist local management subnet and static IP
ignoreip = 127.0.0.1/8 ::1 203.0.113.45
Reload the service: sudo systemctl restart fail2ban.[2]
Pro Tip: Checking Raw Kernel Packet Drops via Iptables
If Fail2ban reports no banned IPs, verify whether raw netfilter rules are silently discarding packets:
sudo iptables -L -n -v | grep -i "22" or sudo nft list ruleset | grep 22. Look for DROP targets linked to your source address.[4]
Configuring Inbound Firewall and Cloud Security Group Ingress
If your IP is unbanned, the server’s local firewall or the hypervisor edge router is blocking port 22.
Step 1: Verify and Configure UFW (Ubuntu / Debian)
# Check UFW status and active rules
sudo ufw status verbose
# Ensure OpenSSH is explicitly permitted
sudo ufw allow 22/tcp comment 'OpenSSH Port'
# Reload UFW firewall
sudo ufw reload
Step 2: Verify and Configure Firewalld (RHEL / AlmaLinux / Rocky Linux)
# Inspect active Firewalld zone configuration
sudo firewall-cmd --list-all
# Permanently permit the SSH service and reload
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-port=22/tcp
sudo firewall-cmd --reload
Step 3: Verify OpenSSH Daemon Listening Port
Ensure sshd is running and bound to all interfaces on port 22:
# Verify SSH service status
sudo systemctl status ssh || sudo systemctl status sshd
# Confirm port 22 is listening across 0.0.0.0
sudo ss -tlpn | grep :22
If the output displays 127.0.0.1:22, the daemon is bound exclusively to localhost. Edit /etc/ssh/sshd_config, ensure Port 22 and ListenAddress 0.0.0.0 are active, and restart sshd:
sudo systemctl restart ssh || sudo systemctl restart sshd
Common Pitfall: Changing Port in sshd_config Without Updating Firewalls
Never change the default port in /etc/ssh/sshd_config (e.g., to 2222) before adding the new port to UFW, Firewalld, and your cloud provider's security group ingress rules. Doing so will immediately sever your connection, resulting in a persistent Connection timed out error upon the next login attempt.[1]
Step-by-Step Server Administrator Remediation Plan
Follow this terminal runbook sequentially to resolve SSH timeout tickets on Linux VPS instances:
[ ] Step 1: Execute 'ssh -vvv user@server_ip' to confirm timeout at TCP SYN phase.
[ ] Step 2: Switch to mobile hotspot/alternative network to rule out local ISP port 22 filtering.
[ ] Step 3: Log into hosting dashboard and launch out-of-band VNC Web Console.
[ ] Step 4: Run 'systemctl status sshd' and confirm the daemon is active and listening.
[ ] Step 5: Check Fail2ban: execute 'fail2ban-client status sshd' and unban client IP.
[ ] Step 6: Verify internal firewalls: run 'ufw allow 22/tcp' or 'firewall-cmd --add-service=ssh'.
[ ] Step 7: Inspect cloud provider dashboard and ensure Inbound Security Group allows TCP 22.
[ ] Step 8: Confirm external network transit: 'nc -zv server_ip 22'.
[ ] Step 9: Re-establish standard SSH session from local terminal.
Frequently Asked Questions About SSH Connection Timeouts
What causes an SSH connection timed out on port 22?
An SSH connection timeout occurs when client packets sent to port 22 receive no response from the destination server.[1] Primary triggers include client IP addresses being banned by Fail2ban, internal Linux firewalls (UFW/Firewalld) dropping traffic, cloud hypervisor security group ingress rules blocking TCP 22, or local corporate firewalls restricting outbound SSH traffic.[1][2]
How do I fix SSH connection timed out on a Linux VPS?
To fix an SSH timeout, log in through your VPS hosting provider’s out-of-band VNC or KVM web console.[1] Once logged in, verify the SSH daemon is running via systemctl status sshd, unban your public IP address using fail2ban-client set sshd unbanip <IP>, and open port 22 in your server firewall using ufw allow 22/tcp.[2]
What is the difference between SSH connection timed out and connection refused?
A Connection timed out error means network packets were silently discarded or blocked by a firewall before reaching an active socket, yielding no reply.[1] A Connection refused error indicates the packet successfully reached the server, but the operating system actively rejected the connection because no service was listening on port 22.[1]
How do I check if my IP is banned by Fail2ban?
Access your server via VNC console and run sudo fail2ban-client status sshd.[2] The output displays the list of currently banned IP addresses under Banned IP list. Remove your IP by executing sudo fail2ban-client set sshd unbanip <your_ip_address>.[2]
Why does SSH timeout on corporate or public Wi-Fi?
Many public Wi-Fi access points (hotels, airports, cafes) and strict corporate networks block outbound traffic on port 22 to prevent unauthorized tunneling and administrative access.[3] Testing your connection through a mobile cellular hotspot or routing SSH through an encrypted WireGuard VPN tunnel will immediately confirm if your local network is filtering port 22.[3]
Deploy Resilient High-Speed Cloud VPS Infrastructure
Eliminate network latency bottlenecks, connection drops, and virtualization limits. Deploy high-performance Linux cloud instances with dedicated IPv4 addresses, out-of-band KVM consoles, and unmetered multi-gigabit uplinks from Nextgen Hosting.
Explore Global Dedicated Servers Explore Pakistan Dedicated ServersDisclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content.
Sources & Official References
- OpenSSH Project. "SSH Connection Diagnostics, Transport Layer Handshakes, and Verbose Debugging." OpenBSD OpenSSH Reference Manual. Available at: https://www.openssh.com/manual.html
- Fail2ban Project. "Fail2ban Client Administration, Jail Management, and Unbanning Procedures." Fail2ban Documentation. Available at: https://www.fail2ban.org/wiki/index.php/Commands
- Ubuntu Documentation. "Uncomplicated Firewall (UFW) Administration and Port Filtering." Canonical Technical Reference. Available at: https://help.ubuntu.com/community/UFW
- Netfilter Project. "Packet Filtering and State Tracking in Linux iptables and nftables." Netfilter Core Team. Available at: https://www.netfilter.org/documentation/
