About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
If you edited /etc/ssh/sshd_config, restarted the SSH service and now get ssh: connect to host 203.0.113.10 port 22: Connection refused, nothing is accepting connections on that address and port. Either the SSH daemon did not start with the new file, or it is listening somewhere else. You need console access to the machine to see which, because the network path you used is gone.
For a VM, the hypervisor console is that access. Once in, run sshd -t to find the error in the file, restore your backup copy, and start the service. The later sections cover how to make the same edit safely next time.
What the error means
In the OpenSSH client source the message is "ssh: connect to host %s port %s: %s", with the system's error text. For Connection refused, the connect(2) manual explains the error code: "ECONNREFUSED: A connect() on a stream socket found no one listening on the remote address." A timeout is a different error (ETIMEDOUT: "Timeout while attempting connection."), so refused and timed out point in different directions. Refused means something answered to say no.
After a configuration change there are four general ways to reach that state, plus a fifth that applies to Ubuntu. In the causes table, a syntax error and missing host keys are both start failures, so both belong to the first way, and a reload that applied a bad file is the second.
- The daemon failed to start. The
sshdsource shows that a bad line in the file is fatal. Typical messages are<file>: line <n>: Bad configuration option: <word>followed byterminating, <n> bad configuration options, orline <n>: Badly formatted port number. - The daemon was reloaded and did not come back. On SIGHUP the daemon logs
Received SIGHUP; restarting., closes its listening sockets and runs itself again, which reads the file again. If the exec fails it logsRESTART FAILED: execpath=...and exits. If the new copy hits a fatal error in the file, no daemon is left. A reload is a restart in this respect. - The daemon could not bind. The source logs
Bind to port <p> on <address> failed: <reason>.for each address, and if none succeeds,Cannot bind any address.and exits. The reason text is the system's, for example an address already in use. - It is listening elsewhere.
Port"specifies the port number that sshd listens on. The default is 22", andListenAddresslimits the addresses. A changed value means port 22 is simply empty.
The fifth case is the Ubuntu one.
Ubuntu and socket activation
A post on Ubuntu Discourse, in the Server documentation category, says that "As of version 1:9.0p1-1ubuntu1 of openssh-server in Kinetic Kudu (Ubuntu 22.10), OpenSSH in Ubuntu is configured by default to use systemd socket activation", which means sshd "will not be started until an incoming connection request is received." For 22.10 to 23.10, on upgrade, Port and ListenAddress settings were migrated to /etc/systemd/system/ssh.socket.d/addresses.conf. In Ubuntu 24.04 LTS they are not migrated: "the port and address settings are pulled dynamically from sshd.conf via a systemd generator".
In that setup, the listening socket belongs to ssh.socket, not ssh.service. Ubuntu's launchpad bug 2069041 records the symptom: "Changing the Port directive in sshd_config and restarting ssh.service is without effect, sshd keeps listening to port 22." The systemctl(1) manual says daemon-reload "will rerun all generators (see systemd.generator(7)), reload all unit files". Because Ubuntu 24.04 takes the port and address from the SSH configuration through a systemd generator, the sequence for a new port is: put the port in a drop-in under /etc/ssh/sshd_config.d/, run systemctl daemon-reload, then systemctl restart ssh.socket. The first comment on the Launchpad bug gives the same sequence, and the bug is marked Fix Released for Noble (24.04): the fix is a comment in the default /etc/ssh/sshd_config saying that a systemctl daemon-reload is needed for changes to Port to take effect when socket activation is used. Ubuntu's server documentation only says to restart ssh.service after a change, so check the sequence on releases other than 24.04.
The systemctl(1) manual adds that while the manager is reloaded, "all sockets systemd listens on behalf of user configuration will stay accessible", so daemon-reload itself does not close the listener.
Disruptive step: systemctl restart ssh.socket stops and re-opens the SSH listener, on a machine you may be connected to over SSH. Do not rely on your current session surviving; keep the console open. If the new Port or ListenAddress is wrong, new connections are refused until you correct the file and repeat systemctl daemon-reload and the restart. Back out by restoring the previous configuration file and repeating both commands.
To listen on only one port, the Discourse thread shows an empty ListenStream= line before the new one. The systemd.socket manual confirms the reason: "If the empty string is assigned to any of these options, the list of addresses to listen on is reset".
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
| Syntax error or unsupported option in the file | Daemon not running; refused on every address | sshd -t names the line; systemctl status ssh.service shows it exited |
| Reload applied a bad file | Worked before the reload; refused after | Log shows Received SIGHUP; restarting. then an error or RESTART FAILED |
Port or ListenAddress changed |
Daemon running; refused only on the old port | ss -ltnp shows sshd on another port or address |
| Socket activation not reloaded (Ubuntu 22.10 and later) | ssh.service restarted, but the listener did not change |
systemctl status ssh.socket; ss -ltnp |
| Bind failed | Bind to port ... failed or Cannot bind any address in the log |
The log line; ss -ltnp for what holds the port |
| Host keys missing or unreadable | Daemon exits at start | The log line no hostkeys available -- exiting. |
Prove the cause before changing anything
You need console access. From the VM console as root:
systemctl status ssh.service
journalctl -u ssh.service -b
sshd -t
ss -ltnp
systemctl status shows whether the service is running. journalctl -u limits output to the SSH unit and -b to the current boot. sshd -t is documented as "Test mode. Only check the validity of the configuration file and sanity of the keys." ss -ltnp lists listening TCP sockets with the process that owns each, so you can see whether sshd is listening and on which address and port. The unit is ssh.service on Ubuntu and may be named sshd.service on other distributions. On Ubuntu, also read systemctl status ssh.socket.
Example (illustrative): On web01 (Ubuntu 24.04), an administrator adds Port 2222 to a drop-in file /etc/ssh/sshd_config.d/port.conf, runs systemctl restart ssh.service, and tries ssh -p 2222 deploy@203.0.113.10: connection refused. From the console, ss -ltnp shows sshd still listening on port 22 only. The administrator runs systemctl daemon-reload and systemctl restart ssh.socket, and ss -ltnp now shows port 2222. The firewall is then checked for the new port before port 22 is closed.
Fix
Restore a valid file
Restore the backup copy of the file you saved before editing, or correct the line sshd -t names, and run sshd -t until it reports nothing.
Disruptive step: restoring a file replaces your newer edits, and starting the service makes SSH reachable again with whatever the file allows. Keep the broken copy under another name so that you can compare. Back out by putting the broken copy back.
systemctl start ssh.service
Port or address
If the daemon is healthy but on a different port, connect to that port. Use ssh -p <port> user@host. If the port was changed by mistake, set Port back, test with sshd -t, and reload.
Disruptive step: a reload re-runs sshd, and a bad file leaves no daemon (see case 2 above). Keep the console open and a copy of the previous file. Back out by restoring the copy and reloading again.
Ubuntu socket activation
After a Port or ListenAddress change on a release that uses ssh.socket, follow the sequence above: systemctl daemon-reload, then systemctl restart ssh.socket; the disruptive-step note above applies to both. To undo socket activation altogether, first copy /etc/systemd/system/ssh.service.d/00-socket.conf and /etc/systemd/system/ssh.socket.d/addresses.conf somewhere safe, because the commands below delete them. The Discourse post gives:
systemctl disable --now ssh.socket
rm -f /etc/systemd/system/ssh.service.d/00-socket.conf
rm -f /etc/systemd/system/ssh.socket.d/addresses.conf
systemctl daemon-reload
systemctl enable --now ssh.service
Risk: this changes how SSH starts at boot and removes drop-in files. The post describes it as reverting to the "previous non-socket-activated behavior". Copy the two saved drop-in files back and run systemctl daemon-reload to go back.
Bind failures
Read the reason in the log. If another process holds the port, ss -ltnp names it. Do not stop an unknown process before you know what it serves.
Confirm the fix
sshd -treports nothing.ss -ltnpshows sshd on the address and port you expect.- From a second machine, open a new SSH session and log in. Keep the console session open until this works.
journalctl -u ssh.serviceshows no error after the change.
What to watch afterwards
A repeatable routine prevents a repeat. Ubuntu's documentation puts it plainly: "Since losing an SSH server might mean losing your way to reach a server, check the configuration after changing it and before restarting the server", with sudo sshd -t.
- Copy first, then edit. Keep the previous file.
- Test, then apply. Run
sshd -tbefore every restart or reload.sshd -Talso prints the effective configuration, which shows the result ofMatchblocks. - Keep a session open. Do not close the session you made the change from until a new session has logged in. Do not rely on an existing session surviving a restart.
- Change the firewall first. If you move the port, allow the new port before you move sshd.
- Know the console route. See "Getting into a Linux server you cannot log in to: rescue targets, rd.break and boot loader passwords" for the rescue options if the console itself is protected.
Read next
Related articles you may want next.
- Backup & RecoveryGetting into a Linux server you cannot log in to: rescue targets, rd.break and boot loader passwordsPlanning console access to a locked-out Linux server: rescue and emergency targets, rd.break, debug shells, and boot loader passwords.Read article
- TroubleshootingSSH "Permission denied (publickey)": what the server log says and what to fixSSH says Permission denied (publickey)? Read the sshd log line, then check authorized_keys modes, StrictModes, AllowUsers and accepted key algorithms.Read article
- HostingRevoke a Departed Administrator's Access Across a Hosted EstateAdministrator left? Inventory every route first, then disable AD and Entra accounts, revoke sessions, remove vCenter and ESXi permissions, SSH keys and shared secrets, with evidence.Read article
Risks and limits
- These commands have not been run or lab-tested. They come from the OpenSSH source, manual pages, Ubuntu documentation and the cited bug record.
- The socket-activation steps apply to Ubuntu 22.10 and later. Ubuntu's server documentation does not describe them, and other distributions use other mechanisms.
- A firewall or network device that rejects the port also produces
Connection refused. Check the network path as well as the daemon. - The quoted messages are from OpenSSH master. Your distribution's version may word them differently.
- Reaching the console may need a hosting provider or hypervisor administrator. A VM whose console is locked needs the recovery routes described in "Getting into a Linux server you cannot log in to: rescue targets, rd.break and boot loader passwords".
Sources
- OpenSSH portable source: sshd.c, servconf.c, sshconnect.c — OpenSSH project, master, no date shown, accessed 18 November 2026
- sshd(8) — OpenBSD manual pages, page dated September 2, 2026, accessed 18 November 2026
- sshd_config(5) — OpenBSD manual pages, page dated October 30, 2026, accessed 18 November 2026
- OpenSSH server — Ubuntu Server documentation, no date shown, accessed 18 November 2026
- SSHd now uses socket-based activation (Ubuntu 22.10 and later) — Ubuntu Discourse, posted August 24, 2022, accessed 18 November 2026
- Bug 2069041: Changing Port in sshd_config requires calling systemctl daemon-reload — Launchpad, comment dated 2024-06-13, status Fix Released for Noble, accessed 18 November 2026
- systemd.socket(5) — man7.org, page shows "HTML rendering created 2026-09-09", accessed 18 November 2026
- systemctl(1) — man7.org, page shows "HTML rendering created 2026-09-09", accessed 18 November 2026
- connect(2) — man7.org, Linux man-pages 6.19, page dated 2026-02-08, accessed 18 November 2026
- ss(8) — Debian manpages, bookworm, source updated 2023-05-22, accessed 18 November 2026
This article was originally published on .