Fix SSH that will not connect
We'll check sshd status, firewall, keys and permissions, and host key issues—or tell you when to escalate.
What you'll need
- Console or physical access to the server (if SSH is down)
- sudo on the server
Step-by-step diagnostic
Quick triage — pick your path
Get started
Choose the option that matches what you see. You can jump straight to that section.
Show full guide
Steps
Goal: Check ssh -v output, sshd status, firewall, and keys.
- Run
ssh -v user@hostto see the exact error. - Good: You see connection refused, timeout, or permission denied. Proceed to Check sshd and firewall or Fix keys and permissions.
- Bad: Run ssh -vv for more detail.
Check ssh -v output
Goal: Identify the failure point.
- Connection refused: sshd not running or not listening on port 22.
- Connection timed out: firewall blocking port 22 or network unreachable.
- Permission denied (publickey): wrong key, bad permissions, or key not in authorized_keys.
- Host key changed: remove old key from known_hosts.
- Good: Error identified. Proceed to the matching section.
- Bad: Run ssh -vv and check the last lines.
Check sshd and firewall
Goal: Confirm sshd is running and port 22 is reachable.
- On the server:
systemctl status sshd(or ssh). Start it if inactive. - Run
ss -tlnp | grep 22to confirm port 22 is listening. - Add firewall rule: ufw allow 22/tcp or firewall-cmd —add-service=ssh.
- From the client:
nc -zv host 22to test reachability. - Good: sshd is active and port 22 is reachable. Proceed to Fix keys and permissions if still failing.
- Bad: Start sshd, add firewall rule, or check network.
Fix keys and permissions
Goal: Correct key file permissions and authorized_keys.
- Client:
chmod 700 ~/.ssh,chmod 600 ~/.ssh/id_rsa(or id_ed25519). - Server:
chmod 700 ~/.ssh,chmod 600 ~/.ssh/authorized_keys. Confirm the client public key is in authorized_keys. - If host key changed:
ssh-keygen -R hostname. - Good: Permissions fixed and key in place. SSH should connect.
- Bad: Re-copy the public key to the server; check server logs with journalctl -u sshd.
When to escalate
Escalate if:
- The server is managed by config management.
- You cannot access the console to start sshd or change the firewall.
- The fix requires network or security policy changes.
Provide ssh -v output and systemctl status sshd.
Verification
ssh user@hostconnects without error.- No “Connection refused”, “Connection timed out”, or “Permission denied”.
- Host key is accepted (or already in known_hosts).
Escalation ladder
Work from the device outward. Stop when the problem is fixed.
- ssh -v Run ssh -v to identify the error.
- sshd and port 22 systemctl status sshd; ss -tlnp | grep 22.
- Firewall ufw allow 22/tcp or firewall-cmd --add-service=ssh.
- Keys and permissions chmod 700 ~/.ssh, 600 ~/.ssh/id_rsa; check authorized_keys.
- Escalate Provide ssh -v output and systemctl status sshd.
What to capture if you need help
Before calling support or posting for help, have these ready. It speeds everything up.
- ssh -v output
- systemctl status sshd output
- ss -tlnp | grep 22
- Firewall rules (ufw status or firewall-cmd --list-all)
- Steps already tried
What does ssh -v show?
Run ssh -v user@host. Note the last error.
You can change your answer later.
Run ssh -vv
Connection refused or timeout?
Connection refused = sshd not listening. Timeout = firewall or network.
You can change your answer later.
Is sshd running and listening?
systemctl status sshd; ss -tlnp | grep 22.
Are key permissions correct?
~/.ssh 700, ~/.ssh/id_rsa 600. authorized_keys 600 on server.
You can change your answer later.
Fix permissions
Host key mismatch?
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED.
You can change your answer later.
Remove old host key
Done
Reviewed by Blackbox Atlas
Frequently asked questions
- Why would SSH not connect?
- sshd not running, firewall blocking port 22, wrong key or permissions, host key mismatch, or network unreachable. Run ssh -v to see the error.
- Can I fix SSH connection failures myself?
- Yes. Start sshd, add firewall rule for port 22, fix key permissions, and remove stale host keys from known_hosts.
- When should I escalate SSH connection issues?
- If the server is managed by config management, you cannot access the console, or the fix requires network or security policy changes.
Rate this guide
Was this helpful?
Thanks for your feedback.