ssh: connect to host port 22: Connection refused
Your Mac reached the server, and the server immediately said no on that port. No SSH service is listening there, or a firewall rejected the connection.
Quick checks
- Check the host name or IP and the port (`-p 2222`).
- Test the port: `nc -vz host 22`.
- Is the server's SSH service running?
Fixes on Mac
Connecting to a Mac? Turn on Remote Login
- On the Mac you connect to: System Settings › General › Sharing › Remote Login on.
- Check it's listening:
sudo lsof -nP -iTCP:22 -sTCP:LISTENshould show launchd or sshd.
Use the right port
- If the server uses a custom port, connect with
ssh -p 2222 user@hostor setPortin~/.ssh/config.
- If the server uses a custom port, connect with
Fixes on Windows
Connecting to Windows
- Install the OpenSSH Server optional feature and start the
sshdservice.
- Install the OpenSSH Server optional feature and start the
Other devices
Linux servers
- Start the service:
sudo systemctl enable --now ssh(orsshd). - Check the listening port:
sudo ss -ltnp | grep ssh. - Check firewalls:
sudo ufw statusor the cloud security group.
- Start the service:
Still not working?
If the server just rebooted, sshd may still be starting. If you changed Port in sshd_config, make sure the firewall allows the new port before restarting sshd, or you can lock yourself out.
See what’s happening
LightAtom's Ports view shows whether your Mac is listening on port 22 when you've turned on Remote Login.
Frequently asked questions
What does SSH connection refused mean?
The host replied that nothing accepts connections on that port. The SSH server isn't running, is on another port, or a firewall actively rejects the connection.
How do I enable SSH on a Mac?
System Settings › General › Sharing › Remote Login. You can limit which users may connect.
What is the difference between refused and timed out?
Refused: the host answered no right away. Timed out: no answer at all, usually a firewall dropping traffic or the host being unreachable.