Pcornel
Linux · Security

Fail2ban

Cheat sheet · https://pcornel.dk/topic.php?topic=2851

Back to the Topic

Answer

Fail2ban watches logs for repeated failures (SSH, web logins) and bans the source address in the firewall for a time.

Remember

Configure jails in /etc/fail2ban/jail.local (not jail.conf). Whitelist management networks with ignoreip. Make sure the jail reads the right log or journal backend. It complements, not replaces, key-only SSH.

First checks

  • sestatus / aa-status — SELinux or AppArmor state
  • ss -tulpn — listening services
  • journalctl -u sshd -g 'Failed' — failed logins
  • ausearch -m avc,user_login -ts today — audit events (auditd)

Verify in this order

failure logged → jail filter matches → count exceeds maxretry within findtime → firewall ban for bantime

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2851

Confirmation

Confirm action

Continue?