Ubuntu – Change SSH Port with Firewall

Having a remote database server with default SSH port, for security purpose it’s better to change it to another custom port

** Let’s check if the default firewall is UFW, you are suppose to see an active status with list of ports:

** As default your SSH port is 22, and will be listed by UFW status as follows:

** Now add the custom port, let’s assume it is 7777:

make sure to run sudo ufw status and see if it appears on the list

** Reload the firewall by running the followig command:

** Now let’s go to ssh config file and change the port:

The port line might be commented, so don’t forget to delete the # and edit the port as the following:

** After this restart the SSH service to apply the updates:

** Lastly check if you can see any result for the custom port 7777:

Very Important
BEFORE exiting the terminal, make a new connection via SSH with the new port to make sure the new port is working properly

I have Ubuntu 20.04.1 LTS and UFW version 0.36;


Hello, I'm Mohammad Daka, software engineer who love coding. In my spare time I blogs about JavaScript,PHP, Chrome Extensions, helpful resources and tools, I'm also working on my own projects. Don't hesitate to contact me at my twitter account: @mohammad_daka :)

Leave a Reply

Your email address will not be published. Required fields are marked *