Change SSH Default Port
January 10, 2025
Written by Sean David Reed
OS/Distro: Ubuntu 24.04.1 LTS
-
Port numbers 1 - 1024 are reserved for system services, so they're best left alone. Choose any port number >1024.
-
Allow the port through the firewall.
$ sudo ufw allow <port>/tcp -
Add the port to the ssh config file.
$ sudo vim /etc/ssh/sshd_configIn Vim, type
/Port 22, which should find the same commented out. Below it, add your port number:#Port 22 Port 1492 # Added by seandavidreed #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: -
Restart ssh.
$ sudo systemctl restart sshd -
Check that the port has been changed.
$ sudo systemctl status ssh
Troubleshooting a problem on Ubuntu 24.04.1 LTS
-
On Ubuntu 24.04.1 LTS, I had trouble getting the default port to actually change using steps 4 and 5. Consulting an answer on Ask Ubuntu (shared above), I got the default port to change.
$ sudo systemctl daemon-reload $ sudo systemctl restart ssh.socket $ sudo systemctl restart ssh.service -
Check that it worked.
$ sudo systemctl status ssh





