SSHd now uses socket-based activation Ubuntu 22.10 or later. Below are 2 options to change the default SSH port.
- Disable socket-based and enable service-based SSH
systemctl disable --now ssh.socket systemctl enable --now ssh.service
- Update the
Port
in/etc/ssh/sshd_config
- Restart the SSH service
sudo systemctl restart ssh.service
-
Create ssh socket dir
mkdir -p /etc/systemd/system/ssh.socket.d
-
Create config
cat >/etc/systemd/system/ssh.socket.d/listen.conf <<EOF [Socket] ListenStream=2022 EOF
This will make SSH listen on ports
2022
and22
. If you want SSH to only listen on port2022
, use the config below.cat >/etc/systemd/system/ssh.socket.d/listen.conf <<EOF [Socket] ListenStream= ListenStream=2022 EOF
-
sudo systemctl daemon-reload
-
sudo systemctl restart ssh.socket
Refs: