Ubuntu 24.04: Changing the SSH Port Now Requires a Reboot

And yet another thing that changed in recent years: When I instantiate a new VM, I usually change the SSH server port. I know, it doesn’t help when it comes to security, but it reduces the number of bots knocking on my door and leaving an entry in /var/log/auth.log. When I recently installed a new VM running Ubuntu 24.04, I noticed that changing the port number in ‘/etc/ssh/sshd_config‘ and then reloading ssh with ‘sudo service ssh restart‘ does not change the port number. A full reboot is required for the change to take effect. WHY???

Looks like at some point, Canonical adopted the systemd way of establishing sockets and launching services for SSH. Now, there’s an additional file ‘/lib/systemd/system/ssh.socket‘, where the port can be configured. However, if the port number is changed in ‘/etc/ssh/sshd_config‘, this seems to take precedence, but only after a reboot.

Gee thanks, yet another configuration file to think about. For details see here and here.