PUBLISHED ON: FEBRUARY 9, 2022
How to Change the SSH Port in Linux
This article discusses how to modify the SSH port number for a server. You may wish to change this for security reasons, for example, or if you utilize a third-party service that needs a certain SSH port number.
Changing the SSH port number
1. To change the port for the SSH server, perform these steps:
- Log in to the server as root using SSH.
- Open the /etc/ssh/sshd config file in your favourite text editor (nano, vi, etc). (nano, vi, etc.).
- Locate the following line: Port 7822
2. Change 7822 to the new port number that you wish to use.
3. Save the modifications to the /etc/ssh/sshd config file, and then quit the text editor.
4. Restart the SSH service using the relevant command for your Linux distribution:
5. For CentOS and Fedora, type:
Copyservice sshd restart
6. For Debian and Ubuntu, type:
Copyservice ssh restart
While still logged in as root, in a new terminal window attempt to log in using the new SSH port number. If the login fails, check your settings. Do not quit your open root session until you are able to log in with the updated settings.