Hello Friends, I have just installed an Ubuntu 24.04 VPS successfully. Then, as usual, I changed the sshd port from 22 to, say, 222 from within /etc/ssh/sshd_config Then, I restarted sshd and checked by issuing netstat -nl You can still see that sshd is still listening on tcp 22! Try it by yourself! It is not joke! So, what is your solution to solve this?
If I remember correctly that line is commented out with # so you need to uncomment that line after changing the port number and then restart it. You might also want to close that old port if you are not using it but that is not necessary.
It requires extra steps from Ubuntu 22.04 onward. In file /usr/lib/systemd/system/ssh.socket, edit this line so that it becomes [Socket] ListenStream=2222 In file /etc/ssh/sshd_config, edit this line so that it becomes Port 2222 Then, run these: sudo systemctl daemon-reload sudo systemctl restart ssh.socket sudo systemctl reload ssh.service
According to https://serverfault.com/a/1159600 that is correct but one must maintain the ListenStream= while adding a new port like 222 below it. Code: [Socket] ListenStream= ListenStream=2222 The contributor said: The line ListenStream= is required that port 22 is no longer used. Without this line, the SSH server would then be accessible via port 22 (default) and 2222.