What is fail2ban and how does it work?
BeginnerProductionSSH & Access Hardening
Answer
fail2ban watches logs (files or the journal) for failure patterns defined in filters, and when an IP exceeds maxretry within findtime, it runs an action, usually adding a firewall ban for bantime.
# /etc/fail2ban/jail.local
[sshd]
enabled = true
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 203.0.113.7
More on SSH & Access Hardening
What are the first sshd_config changes you make on a new production server?BeginnerWhy use a drop-in file in /etc/ssh/sshd_config.d/ instead of editing sshd_config?IntermediateWhy disable SSH password authentication entirely?BeginnerShould you change the SSH port from 22?IntermediateWhat are SSH certificates and why do large fleets use them?AdvancedHow do you restrict what a specific SSH key can do?Advanced