ssh: connect to host x port 22: Connection refused
The server answered, but nothing is listening on the SSH port — sshd isn’t running, it uses another port, or a firewall actively rejects.
Seen on:
Linux
Meaning
“Refused” means a reset came back, so the host is reachable. Usually sshd isn’t installed/started (fresh VM, container), listens on a custom port, or fail2ban/ufw rejects your IP.
Common causes
- sshd not installed or not running
- SSH listening on a non-default port
- Firewall rule rejecting (REJECT) your IP, or fail2ban ban
- Connecting to the wrong host/IP
⚡ Quick fix
- Check from the console: systemctl status ssh
- Use the right port: ssh -p 2222 user@host
- Check ufw/fail2ban for your IP
Detailed fix by platform
Linux
- bash
sudo systemctl enable --now ssh # sshd on RHEL sudo ss -ltnp | grep ssh sudo fail2ban-client status sshd
How to diagnose
- Service — sshd running?
- Port — Listening port
- Firewall — ufw status / fail2ban banned IPs
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Linux
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026