Antes de nada, instalar fail2ban
En Debian o Ubuntu
sudo apt update
sudo apt install fail2ban
En Centos
sudo yum -y install epel-release
sudo yum -y install fail2ban
Crear el fichero jail.local
cp /etc/fail2ban/jain.conf /etc/fail2ban/jail.local
Añadir el siguiente bloque en el fichero jail.local. Hay que poner también ssh a enabled = true
[sshd]
enabled = true
banaction = iptables-multiport
maxretry = 10
findtime = 43200
bantime = 86400
Ejecutar
sudo systemctl restart fail2ban