How to Troubleshoot Common SSH Connection Issues on Ubuntu Servers

How to Troubleshoot Common SSH Connection Issues on Ubuntu Servers

By Anmol Ahuja • July 2025 • Linux, Security, Troubleshooting

When managing Linux servers, SSH connectivity issues are among the most urgent and frustrating to troubleshoot. In this guide, you’ll learn my go-to, step-by-step approach—honed in real-world production environments—to restore secure access fast and with confidence.

Bookmark this for your next SSH emergency!

Table of Contents

  1. Initial Checks
  2. Diagnose Network & Firewall
  3. Verify SSH Daemon Status
  4. Audit SSH Configuration
  5. Analyze System Logs
  6. Check Security Tools (fail2ban, etc.)
  7. Test with SSH Verbose Mode
  8. Pro Tips & Best Practices
  9. Summary & Next Steps

1. Initial Checks

  • Ping your server:
    ping your.server.ip
  • Try connecting from multiple networks (office, mobile, VPN) to rule out local client/firewall issues.
  • Using a custom SSH port? Run:
    ssh -p your_port user@your.server.ip

2. Diagnose Network & Firewall

Check if the SSH port is open:

nc -zv your.server.ip 22

If “refused,” check on server:

sudo ufw status
sudo iptables -L

Cloud Servers: Make sure firewall/security group allows inbound TCP on port 22 from your IP.

3. Verify SSH Daemon Status

  • With console/KVM access: is sshd running?
    sudo systemctl status ssh
  • If not, restart:
    sudo systemctl restart ssh

4. Audit SSH Configuration

  • Edit SSH config:
    sudo nano /etc/ssh/sshd_config
  • Check for:
    Port 22 (or your custom), PermitRootLogin no, PubkeyAuthentication yes, PasswordAuthentication no (if key-only), admin user in AllowUsers
  • Validate config:
    sudo sshd -t
  • Set correct permissions:
    chmod 600 ~/.ssh/authorized_keys
    chown youruser:youruser ~/.ssh/authorized_keys

5. Analyze System Logs

sudo tail -F /var/log/auth.log

Look for lines mentioning authentication failed or connection refused.

6. Check Security Tools (fail2ban, etc.)

  • fail2ban status:
    sudo fail2ban-client status sshd

    Unban your IP or temporarily disable fail2ban for testing.

  • Denyhosts: Check /etc/hosts.deny and /etc/hosts.allow for accidental blocks.

7. Test with SSH Verbose Mode

ssh -vvv user@your.server.ip

This outputs where the connection fails (auth, handshake, etc).

8. Pro Tips & Best Practices

  • Always keep a second SSH session open while modifying configs—don’t close all before confirming success!
  • Backup your config:
    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
  • Restrict SSH in your firewall (allow only trusted IPs).
  • Implement 2FA (Google Authenticator or similar) for all remote access.
  • Regularly review server and fail2ban logs for attack attempts.

9. Summary & Next Steps

The structured troubleshooting approach:

  • Connectivity check
  • Port & firewall check
  • SSH service/config audit
  • Log analysis
  • Check for accidental bans

will solve 99% of SSH connection failures on Ubuntu and most Linux servers.

Use my contact page—I’ll help you decode it!

Written by Anmol Ahuja

For more real-world server guides and troubleshooting, follow infraDecoded.com!

Leave a Reply

Your email address will not be published. Required fields are marked *