How to change the default 22 SSH port on Ubuntu permanently


#!/Short and easy method

$ Replace 5432 with port of your choice and run the command

sudo sed -i 's/^#\?Port .*/Port 5432/' /etc/ssh/sshd_config && sudo systemctl restart sshd

$ Now you can connect to SSH on your new port

$ To connect to non default port SSH server, use parameter -p

$ Example: ssh -p 5432 [email protected]


#!/Manual method

$ Open config file sudo nano /etc/ssh/sshd_config

$ Find the line #Port 22

$ Uncomment it by removing #

$ Do not use popular ports like 80,443,8000,8080,8123 etc

$ Change 22 to your desired port

$ Save and exit by pressing CTRL + X

$ Confirm by pressing Y and ENTER

$ Restart SSHD service sudo systemctl restart sshd

$ Now you can connect to SSH on your new port

$ To connect to non default port SSH server, use parameter -p

$ Example: ssh -p 5432 [email protected]