How to Change SSH Server Default Port on Ubuntu

Changing your SSH Server default port # from 22 to something else is one way to secure your server. This post shows students show to easily do that with Ubuntu.

Students who want to learn how to change SSH server default port # from 22 to something else can follow the steps below.

Although changing the default SSH port number isn’t the only way to protect your server, doing it will add another layer of security to your servers. It’s no secret that SSH servers communicate over port 22. It’s a known port and everyone including hackers know it.

Also port scanners try known ports when scanning for vulnerabilities so changing it adds some layer of protection.

Step 1: Logging on to the SSH Server

With SSH port being default, all you have to do is type ssh root@server_ip_address

ssh root@server_ip_address

You don’t need to specify a port that’s because the SSH client is built with instruction to always communicate over port 22.  When you change the port, you’ll need to to specify the new port number everytime you want to connect.

For example, if you change your SSH port to 10021, this is how you’ll always connect to the server.

ssh root@server_ip_address -p10021

Step 2: Changing SSH Port Number

Now that you know, let’s go and change the SSH server default port # from 22 to 10021. To do that, logon to the SSH server as usual.

Then open SSH default configuration file and make the below change.

sudo nano /etc/ssh/sshd_config

Put a # before current for Port 22

# What ports, IPs and protocols we listen for
# Port 22

Then open port # 10021

# What ports, IPs and protocols we listen for
Port 10021

Save the file and you’re done.

Step 3: Restart SSH Service

After changing the port number, the final step is to restart the server so it picks up the change. To do that, run the commands below.

sudo service sshd restart

That’s it! This his how you change SSH port number.

Remember to always include the new port when connection to your server.

ssh root@server_ip_address -p10021


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.