This skill installs and configures fail2ban on VPS servers to automatically ban IPs exhibiting brute-force attempts and protect services.
npx playbooks add skill mikr13/secure-server-setup-skills --skill fail2ban-setup
Protect the selected logging service without replacing unrelated jails or trusted-address policy. A process that is running may still have an inactive or ineffective jail.
ignoreip values. Review administrator access before testing bans./var/log/auth.log, /var/log/secure, or only journald. For journal-only systems, confirm python3-systemd and the installed SSH filter's journalmatch support.Read [references/fail2ban-filters.md](references/fail2ban-filters.md) when choosing backends, filter modes, custom application filters, or a controlled test.
Install Fail2ban and required backend packages within the authorized scope if absent. Preview [scripts/setup-fail2ban.sh](scripts/setup-fail2ban.sh):
sudo bash scripts/setup-fail2ban.sh --dry-run
Pass --ssh-port for every actual listener when socket activation/custom ports make discovery ambiguous. For an authorized SSH jail change and activation:
sudo bash scripts/setup-fail2ban.sh --apply --activate
The helper writes only jail.d/99-secure-server-sshd.local, selects file polling or the systemd backend, preserves existing ignoreip and other jails, and validates configuration before activation. It uses the installed sshd filter with five failures in ten minutes and a one-hour ban. These are adjustable local policy choices, not universal Fail2ban defaults. Without --activate, the running service is unchanged.
Do not enable recidive or application jails unless their actual log source, filter and ban action are verified. Aggressive SSH behavior is an installed sshd filter mode, not a presumed sshd-aggressive.conf file.
The helper validates merged ban-action ports and TCP coverage. Installed iptables/nftables all-port actions require explicit --allow-allports approval; custom actions that cannot be verified need a manual procedure. Active-service reload and recovery select only sshd. Starting an inactive service loads all enabled jails and must be reviewed accordingly.
sudo fail2ban-client -t and check sudo fail2ban-client status sshd after activation.Report running-service, active-jail, filter-match and actual enforcement evidence separately.
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.