How to change the port of my SSH connection

This tutorial will show you how you can change the port of your SSH connection. This will help you to avoid automated brute-force attacks to your server. To make this change we are going to edit the settings in ‘sshd_config’ file.

Most of the attacks are made by bots, not from a real person and they are targeted to the default services ports. When you change SSH port, the service won’t be attacked by artificial scripts, as it takes to much time the whole ports range to be checked.

Connect to your server with SSH client . Switch to root and type:

and you will see the file opened into VIM editor.
The reason why we use VIM is because it is installed on almost all Unix/Linux based operating systems.
To find the port option type:
‘Esc’ key then ‘:’ and ‘?Port’ and using the ‘n’ key locate this string:

Port 22

This is the default port number for your SSH.

Then type ‘ Esc’ key, then ‘i’ and remove the ‘#’ sing and change the port number from 22 to different one in the range from 2000 to 65535.

To save the changes type ‘Esc’ followed with ‘wq’ and hit Enter.

The sshd daemon must be restarted in order the new changes to take effect with this command:

Now you will be able to connect your machine on the port you have chosen.

Related links: VIM Editor commands

Filed Under: SSH

Anthony Gee About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.

Leave a Reply