Protecting Your VPS with Fail2Ban
Fail2Ban helps protect your VPS from brute-force attacks by banning IPs with too many failed login attempts.
Step 1: Install Fail2Ban
sudo apt update && sudo apt install fail2ban -y
Step 2: Configure Fail2Ban
Create a local jail configuration:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit jail.local
and set rules:
[sshd]
enabled = true
port = 2222
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 600
Step 3: Restart Fail2Ban
sudo systemctl restart fail2ban
Step 4: Check Status
sudo fail2ban-client status sshd
✅ Now your VPS is protected from repeated login attempts.