Yet another entry after a while. Today, I will draft the necessary steps to change SSH Port in Ubuntu 24. These might apply to other version of Ubuntu but tbh, I don’t care.
As in the previous version of Ubuntu / Debian, we normally need to change the listening ports in the sshd_config, and then allowing in the firewall will be fine. However for later Ubuntu such as Ubuntu 24, we need to change the ssh.socket ones. So I will note necessary steps in this article. Assume that we are going to change SSH port to 888.
First, just specifying a custom listening port in /etc/ssh/sshd_config.d/10-custom-ssh.conf to add the custom port as follows
Port 888Next, we need to also edit the ssh.socket info as follows
systemctl edit ssh.socketThe above command will edit the file /etc/systemd/system/ssh.socket.d/override.conf. Then, input the following content
[Socket]
ListenStream=
ListenStream=888Remember that the ListenStream= is required to specify that we do not use the default port 22 any more.
Then, finally just restart both the ssh service and the ssh.socket as follows:
systemctl restart ssh
systemctl restart ssh.socketDo not forget that if you are using any firewall, please open the new port (888) in the corresponding firewall.