Fail2Ban is an intrusion prevention software that monitors log files and bans IP addresses after repeated failed authentication attempts. It helps protect against brute force attacks by blocking malicious IPs for a specified duration, reducing the risk of unauthorized access.
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Copies the default configuration to a local file for customization.
sudo nano /etc/fail2ban/jail.local
Modify settings such as:
[sshd]
enabled = true
maxretry = 3
bantime = 60
findtime = 60
maxretry: Number of failed attempts before banning.
bantime: Duration (in seconds) an IP remains banned.
findtime: Time window for counting failed attempts.
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd
And obviously, our ip got banned.

sudo fail2ban-client set sshd unbanip <IP-ADDRESS>