No More Port and ListenAddress in sshd_config in Ubuntu 22.10+
It is good or bad, but Ubuntu 22.10+ does not use the good old /etc/ssh/sshd_config
for configuring the OpenSSH port and listen address. The latest Ubuntu LTS (long-term support) release is 22.04; thus, LTS releases are not affected yet, but soon they will!
In Ubuntu 22.10+, the SSH server works in the socket mode, and its port and listen address can be configured by editing the ListenStream=<listen-address>:<port>
setting in the /lib/systemd/system/ssh.socket
file (e.g., by specifying ListenStream=0.0.0.0:1234
). Sadly, this file will eventually be overwritten by some next Ubuntu update. As a result, you may be unable to connect to the SSH server because of the wrong port number. (I had this issue several times until I figured out how to solve it.)
In order not to overwrite the file, we can force the Ubuntu updater to write the updated version to some other location. Here is how to do that:
sudo dpkg-divert --no-rename --divert /lib/systemd/system/ssh.socket.diverted /lib/systemd/system/ssh.socket
Then you need to reload systemd configuration (and rebuild its dependency tree/graph) with the command:
sudo systemctl daemon-reload
Finally, you should restart the ssh service (working in the socket mode):
sudo systemctl restart ssh.socket
If you want to revert to the classical non-socket SSH operational mode, the instructions on how to do that can be found here.