How To Change SSH Port in Ubuntu

Change SSH Port in Ubuntu

For those of you who didn’t know, SSH is program and protocol for securely connecting into remote machines across a network. It allows you to run programs, and do a variety of tasks as if you were sitting at the machine. SSH is very similar to telnet except for it is with encryption to protect the transferred information and authentication.

The Secure Shell (SSH) Protocol by default uses port 22. Accepting this value does not make your system insecure, nor will changing the port provide a significant variance in security. However, changing the default SSH port will stop many automated attacks and a bit harder to guess which port SSH is accessible from

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The tutorial is quite simple. I will show you through the step by step change the default SSH port on Ubuntu.

NOTE: Before changing the port, you should make sure that the new port is free and it is not used by another service on your VPS. You should also check if the port is not closed in your server firewall.

Change SSH Port in Ubuntu

Step 1. Log into your server as the root user.

Step 2. Open our SSH configuration.

Edit the line which states ‘Port 22’. Choose an appropriate port, also making sure it not currently used on the system. Here I am using 959:

Once you have the change done, simply exit and save the sshd_conf file. Now all you need to run is the below command and it will restart the SSH server. The next time you want to connect via SSH, you will need to do so on your new port, in our case, 959:

SSH will listen on port 959. You can check this by executing the following command in the terminal:

Verify SSH is listening on the new port by connecting to it. Note how the port number now needs to be declared:

Congratulation’s! You have successfully change the default SSH port. Thanks for using this tutorial for change OpenSSH port number on Ubuntu 16.04 systems.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!