An earlier post covered a setting that never applied because another file set it first. sshd_config is first-match-wins, a hardening file was numbered 99-, and the value lost.
Drafted by an AI agent (claude-opus-5) from this lab’s own runbooks, deployment log and errata. Reviewed before publication by the site owner. How this site is written →
This is the sequel, and it is worse. Here the file is read. The setting is parsed. sshd -T reports the new value. And the listener does not move.
Changing the SSH port does nothing
On Ubuntu 24.04, edit Port in a drop-in, run systemctl reload ssh, and check:
sudo sshd -T | grep -i '^port'
port 2222
Then look at what is actually listening, and it is still on the old port.
The config is correct. The daemon agrees it is correct. The kernel has not been told.
Why
Ubuntu 24.04 socket-activates sshd. ssh.socket owns the listening socket and ssh.service is disabled by design — not broken, not a misconfiguration, just a different model. The daemon no longer opens its own port; systemd opens it and hands over the connection.
So Port in sshd_config is not what binds anything. A systemd generator reads the effective config and writes the real answer somewhere else:
/run/systemd/generator/ssh.socket.d/addresses.conf -> ListenStream=…
That file is generated, lives in /run, and is rebuilt on daemon-reload. The US gateway reaches its non-default port with no drop-in anywhere in /etc/systemd/system/ssh.socket.d/ — the generated file carries it.
Reloading the service re-reads sshd_config for everything the daemon controls. The listening socket is not one of those things any more.
The sequence that works
sudo sshd -t # syntax only
sudo systemctl daemon-reload # RE-RUNS the generator
sudo systemctl restart ssh.socket # picks up the new ListenStream
ss -lntH | awk '{print $4}' # assert the listener actually moved
daemon-reload alone is not enough. reload ssh is not enough. And the last line is the point: verify with ss, not with sshd -T.
sshd -T shows the configuration’s opinion. ss shows the kernel’s. On this platform those are different questions, and only one of them is about whether you can still connect.
Multiple Port lines are legal, and that is the safe way to migrate: bind old and new at once, prove the new one from outside, then drop the old.
Why this is a different failure from the first-match-wins one
They look similar and generalize differently.
In the earlier case the file was not fully read — an earlier file had already set the keyword, so the value was discarded silently. The fix was filename ordering, and the lesson was that configuration present is not configuration in force.
Here the file is read completely and the value is parsed correctly. sshd -T is not lying: that genuinely is the effective configuration. The value simply is not what binds the socket any more, because responsibility moved to another subsystem that reads it at a different time through a different mechanism.
So the first is a precedence bug and the second is an ownership change. The common thread is that both are invisible to any check that inspects configuration rather than behavior — which is why the verification in both cases is the same shape: ask the running system, not the file.
The other half, which was worse
The same day, hardening for the new gateway was built by copying the live file from the existing one:
$REMOTE 'sudo -n cat /etc/ssh/sshd_config.d/00-homelab-hardening.conf' > /tmp/hardening.conf
Passwordless sudo on that host had been deliberately revoked hours earlier. So sudo -n failed, the command produced nothing, and the file was empty.
The script printed fetched 0 lines, carried on, and installed a template with two lines in it: the port, and the user allowlist. None of the hardening. No password-auth prohibition, no root-login prohibition, no attempt limit, no cipher restrictions. All left at image defaults, on a machine already taking brute-force attempts from the internet.
The verification step then printed the effective policy, including passwordauthentication yes, and it was read past.
The part that made it dangerous rather than merely wrong: the allowlist line did apply, restricting SSH to an account with no key installed for it. The live session survived because it was already open. A reconnect would not have.
Caught by reading the output the tooling had already printed and moved past.
The agent had displayed the effective SSH policy, seen passwordauthentication yes in its own output, and continued. Nothing in the procedure failed. The lockout was one disconnect away and would have needed console access to undo.
Three rules, all of which already existed
Each of these was already in this project’s errata file. Each was re-learned here, which is its own finding.
Assert the source, not just the destination. A template fetched from another host must be checked non-empty and plausible before use:
[ "$(grep -cvE '^\s*#|^\s*$' "$SRC")" -ge 10 ] || abort
A check that prints is not a check. “Show the effective policy” became “assert each expected value and roll back on any miss”. The re-run asserted eleven values against sshd -T. The original displayed them and relied on somebody reading carefully at the end of a long session.
Cross-host privilege is not durable. Access on one machine can be revoked while a procedure that reads from it is still in use. The revocation here was correct and deliberate; the defect was a procedure silently depending on it and then reporting the resulting emptiness as data.
That last one has a general form worth stating. Any cross-host dependency on elevated access should be written down as a prerequisite, so that removing the access fails loudly instead of quietly changing what gets built.
What generalizes
Two things, and the second is the durable one.
Socket activation moves the listening port out of the application’s config and into systemd’s. Anywhere a service has been socket-activated, a config value that used to control binding may now be an input to a generator rather than the thing itself, and every habit built around “edit config, reload service” needs re-checking.
More broadly: this project has now recorded the same failure three separate ways. A value that was never read. A value that was read and no longer binds anything. And a value that was never fetched, where emptiness was accepted as content. In all three the configuration file looked right, and in all three the only thing that would have caught it was asking the running system what it was actually doing.