Monday, October 3, 2022

How to change SSH port in Ubuntu

In this article, we want to teach you how to change the SSH port in Ubuntu.

The SSH protocol (also referred to as Secure Shell) is a method for securing remote login from one computer to another. It provides several alternative options for strong authentication, and it protects the communication’s security and integrity with strong encryption. It is a secure alternative to the non-protected login protocols (such as telnet, rlogin) and insecure file transfer methods (such as FTP).
The default port of the SSH service is 22, it’s better to change the default SSH port to increase the security of your server.

How to change the SSH port in Ubuntu

It is a very easy task to change the port for the SSH service. In Ubuntu 20 or other versions of the Ubuntu ecosystem you can check the current configuration with the following command:

grep -i port /etc/ssh/sshd_config

If you want to change the default SSH port, use the following command:

sudo vi /etc/ssh/sshd_config

After entering the above command, we will see the contents of the sshd_config file.
Next, you need to change the specified number 22 to another value (for example port 3823). We also need to remove the # character from the beginning of this line to use this line as an active operating command on the server.

Restart the SSH server with the following command:

systemctl restart sshd

After that, run the netstat command and make sure that the ssh daemon now listens on the new ssh port:

netstat -pnltu | grep ssh

You’ll see this output if you configure the ssh port correctly.

 [email protected]:~# netstat -pnltu | grep ssh
tcp 0 0* LISTEN 18321/sshd
tcp6 0 0 :::3823 :::* LISTEN 18321/sshd

Allow the new SSH port on the UFW firewall

Here you can allow the new port through the firewall. Run the following command:

sudo ufw allow 3823/tcp
sudo ufw reload

Now you can exit and sign in using a new port with the following command.

ssh –p 3823 [email protected]


At this point, you know about SSH and what is used. and you can easily change its port in Ubuntu.

Hope you enjoy this article about how to change the SSH port in Ubuntu.
Stay tuned for more articles.

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles