frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[Beginners] How to change SSH Port on Linux VPS?

ReginaRegina Moderator
edited August 2019 in Various Tutorials

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:

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, 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.

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch