Best Offers:


blog single post
Courses

How to change SSH Port on Linux VPS?



This tutorial will provide you 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 a note, that new port number should not be used by other service or 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:

1.Login to your Linux VPS via SSH as root user. You can do it via terminal/shell or use SSH client, for example, PuTTY.

2. Copy the command:

vi /etc/ssh/sshd_config

3. Find the line with information:

# Port 22

4. Remove the # symbol and change "22" into your wanted port number. 

5. Save and exit the file (Press "Esc" then enter :wq).6. Restart your sshd service by running command bellow:

For CentOS 6, Debian 8, Debian 9:

service sshd restart

For CentOS 7:

systemctl restart sshd.service

For Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04:

service ssh restart

From now on, you will be able to connect via SSH using your newly updated port number.

 

Changing SSH Port On Fedora 28

1. Login to your Linux VPS via SSH.

2. Copy the command:

vi /etc/ssh/sshd_config

3. Find the line with information:

# Port 22

4. Remove the # symbol and change "22" into your wanted port number.

5. Save and exit the file (Press "Esc" then enter :wq).

6. 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"

7. Restart the firewall and SSH service:

firewall-cmd --reload; systemctl reload sshd

From now on, you will be able to connect via SSH using your newly updated port number.