How to change your SSH port from the default of 22 on Ubuntu 14.04

A little security through obscurity by changing the SSH (Secure Shell) port on your server from the default of 22.

 Posted January 7, 2017

This page explains how to change the SSH (Secure Shell) port from the default of 22. Using port 22 doesn’t make your system insecure, nor will changing the port from 22 provide any significant variance in security. However, changing the default SSH port will help stop many automated attacks by making it a bit harder to guess which port the secure shell (SSH) is accessible from. In other words, security though obscurity.

1. Connect to your server via SSH

Connect to your server using an SSH client such as PuTTY (for Windows) or OpenSSH for Mac/Linux

2. Edit the /etc/ssh/sshd_config file using root permissions

To edit the file using ‘nano’:

3. Locate the line that looks like one of the following:

4. Edit the line to remove the # and change 22 to the SSH port number you’d like to use.

For example:

Save and exit. If using nano, press Control-X, then Y, then hit Enter.

5. Restart the sshd service on your server

Type the following command:

You should see something like this:

6. Ensure that you’re able to connect using the new port.

Before disconnecting, we recommend verifying that you’re able to connect using the new port. If you can’t, try repeating the above steps with another port or switch back to 22.

Use your your preferred SSH client (see Step #1) or type the following from your existing shell, replacing 59522 with the port number chosen in Step #4:

For more information:

Leave a Reply

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