In this tutorial i’ll show you how to change the ssh port. I will also explain how you can fix the issue that the port wont change on after reboot.
Login into your vps
ssh root@yourip
In this case we’re using Ubuntu 22.04
Edit the ssh config:
sudo nano /etc/ssh/sshd_config
If sudo is missing install it
apt-get update && apt-get install sudo
The file should look like:
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
Change the line „#Port 22“ to „Port 1337“ to change the ssh-port to 1337.
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
Port 1337
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
Now restart ssh to apply changes:
sudo systemctl restart ssh
If you’re using terminal you can now check if it worked by running:
ssh root@yourip -p1337
Sometime you’ll notice that the port has changed to default after reboot. To fix this issue run the following commands:
systemctl disable ssh.socket
systemctl enable ssh
reboot
After running theese commands the port change will apply.