Home/Hosting/Virtual Servers/Manage/Connect/Linux server/Change port for SSH connections
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:
cd /etc/ssh/
Open the SSH configuration file with root privileges using this command:
sudo nano sshd_config
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:
sudo systemctl restart ssh
For FreeBSD, use:
sudo service sshd restart
Add a rule to permit traffic exchange on the new port using the command:
sudo ufw allow 2233
Replace “2233” with the chosen port.
Verify if everything is functioning properly by using the command:
telnet 8.8.8.82233
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.
Was this article helpful?
Not a Gcore user yet?
Enhance your online presence with our virtual and dedicated servers.