Installing and configuring Fail2ban on your VPS server running Debian 12 or Ubuntu 24.04 is crucial for securing your server against brute force attacks. Follow the steps below to set it up.
Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
Step 2: Install Fail2ban
To install Fail2ban, run the following command:
sudo apt install fail2ban -y
Step 3: Configure Fail2ban
After installation, you need to configure Fail2ban. The main configuration file is located at:
/etc/fail2ban/jail.conf
It is recommended to create a copy of this file to customize your settings:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit the local configuration file:
sudo nano /etc/fail2ban/jail.local
In this file, you can configure the settings for various services. For example, to enable SSH protection, ensure the following lines are included:
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
bantime = 3600
Step 4: Start and Enable Fail2ban
Start the Fail2ban service and enable it to start on boot:
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
Step 5: Check Fail2ban Status
To check the status of Fail2ban and see if it is protecting your services, use:
sudo fail2ban-client status
Step 6: Monitor Fail2ban Logs
You can monitor the Fail2ban logs for any activity:
sudo tail -f /var/log/fail2ban.log
Conclusion
By following these steps, you have successfully installed and configured Fail2ban on your VPS server running Debian 12 or Ubuntu 24.04. This will help protect your server against unauthorized access and enhance its security!