Looking to secure your VPS from brute-force attacks with minimal effort? This script by Hosteons makes it easy to automatically install Fail2Ban and configure it based on the services running on your server.
Script Features:
-
Installs Fail2Ban if not already installed
-
Detects installed services such as SSH, Apache, or Nginx
-
Automatically enables relevant jails only
-
Compatible with Ubuntu, Debian, CentOS, and AlmaLinux
-
Skips jails for services not found
-
Safe to run multiple times — idempotent setup
-
Configures jail paths based on your OS (e.g., /var/log/auth.log or /var/log/secure)
-
Auto-restarts Fail2Ban and verifies the setup
Usage Instructions:
-
Connect to your VPS via SSH as the root user.
-
Download the script:
wget https://raw.githubusercontent.com/hosteons/Fail2Ban-Auto-Installer-With-Jail/main/fail2ban_auto_installer.sh
3. Make it executable:
chmod +x fail2ban_auto_installer.sh
4. Run the script:
./fail2ban_auto_installer.sh
The script will automatically install Fail2Ban (if not already installed), detect services like SSH or Nginx, and configure only the necessary jails. It will also display which jails are active after setup.
Important: Ensure you have root or sudo access. If you’re using a minimal OS install, make sure wget is available.
GitHub Repository
Visit the GitHub page for latest updates, changelog, and source code:
https://github.com/hosteons/Fail2Ban-Auto-Installer-With-Jail