This quick guide will teach you how to change the SSH port on Linux. This an essential step to secure your server.
PLEASE READ BEVOR DOING ANYTHING !!!
IF YOU MESS UP THOSE CHANGES YOU WILL NO LONGER BE ABLE TO LOGIN INTO SSH / SFTP. PAY ATTENTION TO THE CORRECT SETTINGS.
IF YOU USE A FIREWALL LIKE NFTABLES OR UFW, CHANGE TO SSH PORT TOO PREVENT YOURSELF FROM LOCKING OUT.
Login to SSH as root and change the port
Now edit the config file sudo nano /etc/ssh/sshd_config.
Search for the line Port 22 and change it to whatever you want. The port should be between 1024 to 65535.
After that restart the SSH service and try to login with the new port.
sudo systemctl restart sshd
You may double check If the service start again.
sudo systemctl status sshd
This guide was last updated on May 02, 2026.