VPS one-click scripts
All scripts / Tutorials / fail2ban

Fail2ban SSH Protection Tutorial

This tutorial shows how to enable Fail2ban auto-banning for SSH on a VPS with xyz.sh/fail2ban.

Command
$ curl -fsSL xyz.sh/fail2ban | bash

Details · xyz.sh/fail2ban · Last updated:

Prerequisites

Root access; CentOS / Rocky / AlmaLinux need access to EPEL.

sshd managed by systemd (the default on common VPS images).

Steps

Optional: read the source with curl -fsSL xyz.sh/fail2ban.sh and compare xyz.sh/fail2ban.sh.sha256.

Preview: curl -fsSL xyz.sh/fail2ban | bash -s -- --dry-run

Install and enable: curl -fsSL xyz.sh/fail2ban | bash -s -- -y

Customise: --maxretry 3 --bantime 24h --findtime 10m --ignoreip 203.0.113.5

See bans: curl -fsSL xyz.sh/fail2ban | bash -s -- --status

How to verify

Run fail2ban-client status sshd to see failures and banned IPs, or curl -fsSL xyz.sh/fail2ban | bash -s -- --status.

How to undo or uninstall

curl -fsSL xyz.sh/fail2ban | bash -s -- --uninstall -y removes xyz-sshd.local and restarts fail2ban; to remove the package too, run apt-get remove fail2ban or dnf remove fail2ban.