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 change that editing 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 the port the shh service won’t be attacked by artificial scripts, as it takes to much time the whole ports diapason to be checked.
The tutorial is written for Red Hat Linux like operating systems " Fedora, CentOS etc.
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 65500.
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