Table of contents

Subscribe to our newsletter.
No spam
100% Great content
Unsubscribe anytime

How to change your SSH port

When it comes to changing the SSH port, it is just one of the steps that you need to undertake in order to ensure better security for your server(s). By default the port is set to 22 and not changing these default settings could result in your server being susceptible to online attacks.

Changing the default settings is easy and in this tutorial we are going to show you how to change your port in just a few steps!

Log in through SSH

Firstly, you will need to have access to your server. Because of this, you are going to need to log in through SSH. Simply open up your preferred SSH client or type the following command into your terminal:

ssh root@your_server_ip

IMPORTANT: You need to replace ‘your_server_ip’ with your server’s IP address!

If you are not familiar with SSH, you can follow our detailed tutorial on how to create a SSH key.

How to change the SSH port

Once you have successfully logged into your server, you will need to change the ‘/etc/ssh/sshd_config’ file.

IMPORTANT: Make sure to make a backup of this file before making any changes! To make a copy of the file use this command:

cp /etc/ssh/sshd_config /etc/ssh/sshd_config_

Once you have made a copy of the file, open the config with your preferred editor. For this tutorial, we are going to be using ‘vim’. The command to run vim is:

vim /etc/ssh/sshd_config

You should now see a screen similar to this:

changing the SSH port

You should immediately be able to identify the line that corresponds to the SSH port - Port 22.

If this line commented out (has a # sign before Port 22), you will need to remove the #. Next, to edit the file, press ‘i’. This will switch the system into editing mode. You can now edit the file and change the SSH port to something like 22002 or another port that you like.

IMPORTANT: Don’t set the port to another one which is already in use!

Finally, press the [ESC] button and type ‘:x’ to save and exit vim.

Restart the SSH service

In order for your changes to be applied, you will need to restart the sshd service. You can do so with this command:

service sshd reload

IMPORTANT: Make sure to check whether your server has a firewall installed! If it does, check the rules and make sure to add your new SSH port to the firewall configuration settings. If you don’t, you will not be able to connect to your server via SSH!

You can also use the following command to check the syntax:

sshd -t

If you experience any problems while changing your SSH port, feel free to contact our technical support team!

Deploy your server today!

Get started
Payment methods we accept:
Lightning Network (Bitcoin)
Credit card
Bank transfer