Connect
Change the port for SSH connections
Follow these instructions to modify the SSH port through which you connect to your Linux server.
-
Log in to your server.
-
Navigate to the SSH directory using the following command:
- Open the SSH configuration file with root privileges using this command:
- Find the Port line in the open file and replace the value 22 with the port number you want to use. Also, remove the # symbol if it is present before the Port line.
-
Press Ctrl+O to save the changes.
-
Restart the SSH service. For Ubuntu, Debian, or CentOS, use the following command:
For FreeBSD, use:
- Add a rule to permit traffic exchange on the new port using the command:
Replace “2233” with the chosen port.
- Verify if everything is functioning properly by using the command:
Replace “8.8.8.8” with your server IP address, and “2233” with the chosen port.
The output should look like this:
- Attempt to establish a connection to your server using the new port in a separate window without closing your current session. This step is crucial to prevent any potential loss of access to your server. If you encounter difficulties connecting to your server through the new port, revert the port back to 22 and then try again.