Is there such a script that blocks IPs that try more than 3-4 times to access root? Because everytime I open the server (CentOS) i get the message that root has been brute forced (bots obviously). I have their IPs but I don't want to manually ban them with iptables -A INPUT -s IP-ADDRESS -j DROP
.
1 Answer
The standard tool for the job is fail2ban
. It bans for a certain time an IP address that tried to login unsuccessfully, and it is highly configurable.
It is not available on the standard CentOS repositories, you have to install the EPEL repo first.
On CentOS 6:
yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
On CentOS 7:
yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm
and then:
yum install fail2ban
Note: it is highly recommended that you disable root login (this is done in the configuration of sshd
).
-
Worked like a charm with it. Also works if you install it by Plesk web host edition. Jul 20, 2016 at 10:14
fail2ban
orDenyHosts
is your friendPermitRootLogin prohibit-password
in/etc/ssh/sshd_config
. Alternatively, useforced-commands-only
and have different keys in~root/.ssh/authorized_keys
to run different things as root. remote root access without going via a user and sudo can be useful.~/.ssh/authorized_keys
.