Change SSH port on Ubuntu 22 and newer

On the latest Ubuntu it’s no longer possible to change SSH port in /etc/ssh/sshd_config as SSH deamon is now socket based.

To change the port you need to create a file in /etc/systemd/system/ssh.socket.d/ called listen.conf and specify the new port there.

mkdir -p /etc/systemd/system/ssh.socket.d

Content of listen.conf:

[Socket]
ListenStream=
ListenStream=2245

.. to set the new port to 2245.

sudo systemctl daemon-reload
sudo systemctl restart ssh