SSH Socket

systemctl edit

sudo systemctl edit ssh.socket
# ubuntu 24.04
[Socket]
ListenStream=
ListenStream=2222

# ubuntu 24.10
[Socket]
ListenStream=
ListenStream=0.0.0.0:2222
ListenStream=[::]:2222
sudo systemctl restart ssh.socket

Another way to change port

source

You might need to update the ListenStream config in /etc/systemd/system/sockets.target.wants/ssh.socket.

Change it from:

[Socket]
ListenStream=22
Accept=no

To:

[Socket]
ListenStream=2222
Accept=no

I recommend a diff and higher port though.

After the changes, you will need to reload the systemctl daemon and restart ssh.

sudo systemctl daemon-reload
sudo systemctl restart ssh

Another approach: disable socket

source

sudo systemctl disable --now ssh.socket
sudo systemctl enable --now ssh.service
sudo systemctl restart ssh sshd