Change the SSH Server Port in Ubuntu Linux – 3 Easy Steps

In this article, we want to teach you how to Change the SSH Server Port in Ubuntu Linux. The SSH protocol (also known 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.

SSH is a secure alternative to 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. You can now proceed to the following steps provided by the Orcacore website to Change the SSH Server Port in Ubuntu Linux.

Steps To Change the SSH Server Port in Ubuntu Linux

It is a very easy task to Change the SSH Server Port in Ubuntu Linux. To do this, you must log in to your Ubuntu server as a root or non-root user with sudo privileges. Then, proceed to the below steps to complete this task.

Step 1 – Check the Current SSH Configuration in Ubuntu

First of all, you can start by checking your current SSH configuration. To do this, you can run the command below:

sudo grep -i port /etc/ssh/sshd_config

If your SSH port is still 22, you can easily change the SSH Server Port in Ubuntu Linux.

Step 2 – Change SSH Port Ubuntu

If you want to change the default SSH port, you need to open the SSH config file with your desired text editor like Vi Editor or Nano Editor:

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.

Port 3823

When you are done, save and close the file.

Restart the SSH server with the following command to apply the changes:

sudo systemctl restart sshd

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

sudo netstat -pnltu | sudo grep ssh

You’ll see this output if you configure the SSH port correctly:

Output
tcp 0 0 0.0.0.0:3823 0.0.0.0:* LISTEN 18321/sshd
tcp6 0 0 :::3823 :::* LISTEN 18321/sshd

Step 3 – Allow new SSH port on Ubuntu UFW firewall

At this point, you must allow the new port through the UFW firewall. To do this, run the following commands:

# 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 user@ip-address

Conclusion

At this point, You have learned to increase your security logins by changing the SSH port on the Ubuntu server. You can easily do it by editing the SSH config file, and changing the default port number, and allowing it through your Ubuntu server’s firewall.

Hope you enjoy this guide on Change the SSH Server Port in Ubuntu Linux.

You may also like the following articles:

Change SSH port on AlmaLinux

Change SSH port in Centos 7

SSH Port Number Change on Debian

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!