How To Change The Default SSH Port On Linux Server
The default port for SSH, which stands for Secure Shell, is port 22. It is not a major security issue if you leave this as is, but it is recommended that you change it as an added security measure. A non-default SSH port will help you stop many automated attacks and make it a little harder for hackers to guess which SSH to access from.
How To Change Default SSH Port
Connect to your server via SSH and type in the following command to edit the sshd configuration file.
Look for line that read as follow:
22 with a port between 1024 and 65536
Note: Make sure the new SSH port does not conflict with any known or blocked ports. If you do not know which port is safe to use, just pick from dynamic and/or private port, which are ports from
So if you want to change SSH port to 49456, it will looks like the following:
Save and close the file. Now you need to restart the sshd service by running one of following commands, depending on what Linux distribution you are using:
How to Restart SSH Service for CentOS / RHEL / Fedora / Redhat
service sshd restart
How to Restart SSH Service for Debian / Ubuntu
service ssh restart
sudo service ssh restart
sudo systemctl restart ssh
How to Restart SSH Service for FreeBSD
How to Restart SSH Service for OpenBSD
You have now successfully changed the SSH port. Now try to connect to the SSH with the newly changed port to verify that it works.