Current Article:

How to change SSH default port on Ubuntu 22.04 or later?

How to change SSH default port on Ubuntu 22.04 or later?

Your options for changing from default port:

  • Turning off this change and reverting to how SSHd worked prior to this update:
    • systemctl disable --now ssh.socket
    • systemctl enable --now ssh.service
    • Then the /etc/ssh/sshd_config works again with Ports and Addresses setting
  • OR Listening socket stream update
    1. mkdir -p /etc/systemd/system/ssh.socket.d
    2. cat >/etc/systemd/system/ssh.socket.d/listen.conf <<EOF
      [Socket]
      ListenStream=
      ListenStream=1234
      EOF
      
    3. sudo systemctl daemon-reload
    4. sudo systemctl restart ssh.socket

It should then state it’s started listening on the new port: systemctl status ssh