07-01-2018, 01:32 AM
Step 1 Choose a random number between 49152 and 65535
Step 2 SSH into your VPS - if you don't have NANO already loaded with CentoS - you can do it with this command:
Step 3 Use this command to edit the port number
With nano you'll be able to scroll with your up and down keys to:
#Server 22
Delete # and replace 22 with your random number. Remember to make a note of the new number.
Step 4 Save the change with 'ctrl o' and exit with 'ctrl exit'
ctrl exit
Step 5 Change IP tables (replace "newnumber" with your new port number):
If you have a Panel, you also need to go into the Panel and in the case of VestaCP there was a separate setting for Firewall SSH port number - which I changed from 22 to my new number. I also had other issues with VestaCP which I reported in the last post of this tutorial. VestaCP is still far from perfect, but I think it could possibly also be because of CentOS 7 (probbly still prefer CentOS 6) - VestaCP httpd and nginx have error issues that come up when ports are changed over and above the ones that have been covered above that come up with this message - resulting in one can't restart either httpd or nginx and websites of course are down as a result:
Step 6
Feedback: After the change of the port number I had no more bad login attempts. This really works well.
Step 2 SSH into your VPS - if you don't have NANO already loaded with CentoS - you can do it with this command:
Code: (Select All)
yum install nano
Step 3 Use this command to edit the port number
Code: (Select All)
nano /etc/ssh/sshd_config
With nano you'll be able to scroll with your up and down keys to:
#Server 22
Delete # and replace 22 with your random number. Remember to make a note of the new number.
Step 4 Save the change with 'ctrl o' and exit with 'ctrl exit'
ctrl exit
Step 5 Change IP tables (replace "newnumber" with your new port number):
Code: (Select All)
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport newnumber -j ACCEPT
Code: (Select All)
iptables -A INPUT -j DROP -p tcp --dport 22
Code: (Select All)
/etc/init.d/iptables save
If you have a Panel, you also need to go into the Panel and in the case of VestaCP there was a separate setting for Firewall SSH port number - which I changed from 22 to my new number. I also had other issues with VestaCP which I reported in the last post of this tutorial. VestaCP is still far from perfect, but I think it could possibly also be because of CentOS 7 (probbly still prefer CentOS 6) - VestaCP httpd and nginx have error issues that come up when ports are changed over and above the ones that have been covered above that come up with this message - resulting in one can't restart either httpd or nginx and websites of course are down as a result:
Quote:See "systemctl status httpd.service" and "journalctl -xe" for details.
Step 6
Code: (Select All)
service sshd restart
Feedback: After the change of the port number I had no more bad login attempts. This really works well.