How to Change SSH Port in Ubuntu 20.04

In this article, I will show you how to change SSH Port in Ubuntu 20.04 for your server’s security. I will make 43030 the new SSH Port.

Open New SSH Port

Please note that it is crucial to know if you have Firewall installed (in most cases, I would say “yes”), you must add a rule to allow new SSH port! Otherwise, you won’t be able to use SSH to connect to your Ubuntu server.

You can do so by running the following command:

sudo ufw allow 43030/tcp

Change SSH Port by modifying sshd_config

First, we are going to open sshd_config file with nano.

nano /etc/ssh/sshd_config

You will find a line of codes:

#Port 22

Change the code to the following (unmute and change port):

Port 43030

And then we are going to restart SSH server so that the new config is in effective:

systemctl restart sshd

Connect to Your Server with the new port

You can run the following command with option p to connect to your server:

ssh root@your_id_or_hostname -p 43030

Leave a Reply