Systems & Servers

How to Fix SSH Connection Timeout Errors Due to Firewall Rules

The time limit reached error on port 22 (ssh: connect to host ... port 22: Connection timed out) occurs when the destination server's firewall (typically IPTables or UFW on Ubuntu/Debian) silently drops or blocks incoming network packets on port 22, preventing client authentication.

QUICK DIAGNOSTICS // RESOLUTION MATRIX

[TELEMETRY]
CAUSA
iptables or UFW firewall rules blocking SSH port (22)
SOLUTION
Allow SSH port 22 in firewall: sudo ufw allow 22/tcp
CAUSA
SSH server daemon not listening on expected IP address
SOLUTION
Check SSH daemon status: sudo systemctl status sshd

Step-by-Step Solution

  1. 1

    Step 1: Diagnose if the SSH port is blocked or closed

    Perform a direct network check towards the server's port from your local terminal to verify if it responds to TCP handshakes:

    BASH
    # Check port 22 (SSH) status on your remote server
    nc -zv 192.168.1.100 22
    

    (If the output returns "Connection timed out" or hangs indefinitely, the port is being blocked by a local or cloud network firewall).

  2. 2

    Step 2: Allow SSH traffic in UFW (Uncomplicated Firewall)

    If your server uses UFW, explicitly allow secure remote access and reload kernel rules:

    BASH
    # Allow incoming TCP traffic on the default SSH port
    sudo ufw allow 22/tcp
    
    # Enable UFW if inactive, then reload active rules
    sudo ufw enable && sudo ufw reload
    
  3. 3

    Step 3: Configure explicit rules in IPTables

    If you do not use UFW or need fine-grained rules in raw IPTables, open port 22 directly in your input chain:

    BASH
    # Accept incoming TCP packets on port 22
    sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    
    # Save the active rules to persist across system reboots
    sudo iptables-save | sudo tee /etc/iptables/rules.v4
    

Prevention Advice

Recommended security practices:

  • Do not expose your default SSH port (22) openly to all Internet IP addresses (0.0.0.0/0). Doing so will saturate your authentication logs with automated brute-force attempts in minutes. Instead, restrict access to your specific subnet or VPN IP range, or change the listening port in /etc/ssh/sshd_config to a non-standard one.
Author • Web Designer & App Creator

Rodolfo Castro

Web designer, app developer, and founder of SoporteCero. Specializing in UI/UX architecture, digital products, and modern web environments (Pixel Digital Dz). Every tutorial and guide on SoporteCero is thoroughly tested and verified in our technical lab to ensure reliable, up-to-date solutions.