This tutorial will provide you with a few simple steps on how to change your server's SSH port from default 22 to any other port. This is highly recommended in order to increase your server security. Please take note that a new port number should not be used by any other service or be blocked by your server firewall rules.
Changing SSH Port On CentOS 6, CentOS 7, Debian 8, Debian 9, Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04:
To change SSH port on operating systems mentioned above, complete the following steps:
Login to your Linux VPS via SSH as root user. You can do it via terminal/shell or use SSH client, for example, PuTTY.
Copy the command:
- Find the line with information:
# Port 22
Remove the # symbol and change "22" into your wanted port number.
Save and exit the file (Press "Esc" then enter :wq).
Restart your sshd service by running command bellow:
For CentOS 6, Debian 8, Debian 9:
For CentOS 7:
systemctl restart sshd.service
For Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04:
From now on, you will be able to connect via SSH using your newly updated port number.
Changing SSH Port On Fedora 28
Login to your Linux VPS via SSH.
Copy the command:
- Find the line with information:
Port 22
Remove the # symbol and change "22" into your wanted port number.
Save and exit the file (Press "Esc" then enter :wq).
Create new rule in Fedora's firewall allowing to connect via SSH using your new port number. Change "22" to your new port number:
firewall-cmd --permanent --service="ssh" --add-port "22/tcp"
- Restart the firewall and SSH service:
firewall-cmd --reload; systemctl reload sshd
From now on, you will be able to connect via SSH, on your Linux VPS, using your newly updated port number. If you have any questions, or have trouble completing the provided steps, please leave us a comment or contact our 24/7 customer service. We will gladly answer any inquiries you may have.