Changing Default SSH Port (22) is recommended to avoid bot attacks, brute-force attacks, and several hacking attacks on server. Most of the hosting companies offer default 22 port which is well known by hackers, so you might have seen a message on your SSH something like that: “There were 47183 failed login attempts since the last successful login.”
If you are getting this kind of message in your SSH, then you need to change your port to secure your server. So, let’s do this.
Note: If you are using an internal or external firewall, then add the new port before changing the port, otherwise you will be locked out.
1.At first, you need to login to your SSH. Then type the following command:
sudo vi /etc/ssh/sshd_config
2. Then locate the line where read as follow (press “Enter” key or “i” key on your keyboard to start editing) and if you find “#” before the text then remove that:
3. Change the port to any number between 1024 and 65535. Then to save the file enter “Esc” key on your keyboard and then type:
4. Then you need to restart the service by below command:
service sshd restart
5. That’s it.