Ordered by how often each one turns out to be the answer.
sshd is not running, or not installed
CommonThe server rebooted without starting SSH, the service crashed, or a minimal image never had an SSH server.
Confirm
sudo ss -tlnp | grep -E ':22\b'
On the server: no line means nothing listens on port 22
Fix
- Start it: on Debian and Ubuntu the unit is ssh (sudo systemctl enable --now ssh); on Red Hat-family systems it is sshd.
- If no SSH server is installed, install your distribution's openssh-server package.
You are connecting to the wrong port
CommonThe server runs SSH on another port, or your ~/.ssh/config sets a Port for this host that is out of date.
Confirm
ssh -G HOST | grep -E '^(hostname|port) '
The port ssh will actually use, to compare with the port the server listens on
Fix
- Use the right port with ssh -p PORT HOST, or correct the Port line for that Host in ~/.ssh/config.
Port changed on Ubuntu 24.04, but the socket still listens on the old one
OccasionalWith socket activation, systemd owns the listening socket. A new Port in sshd_config is picked up by a generator only after daemon-reload, and the socket must be restarted. Documented by Ubuntu; not reproduced here.
Confirm
systemctl is-active ssh.socket; sudo ss -tlnp | grep -E 'ssh|systemd'
ssh.socket active and listening on a port other than the one in sshd_config
Fix
- Apply the new port: sudo systemctl daemon-reload, then sudo systemctl restart ssh.socket. Keep your current session open until a new connection on the new port works.
A firewall or security policy rejects the connection
OccasionalA host firewall set to reject, rather than drop, answers with a refusal even though sshd is running. (A firewall that drops packets gives a timeout instead.)
Confirm
sudo ss -tlnp | grep -E ':22\b'
sshd is listening on the server, yet connections from outside are refused
Fix
- Allow your address on port 22 in the host firewall, then try again.
In a container or VM, the port is not published or forwarded
Occasionalsshd listens inside the container or VM, but nothing maps the host's port to it, so the host has nothing listening.
Confirm
nc -vz HOST PORT
Refused on the host's port while sshd runs inside
Fix
- Publish or forward the port (for a container, the port mapping when it starts), then connect to the host's port.