SSH bruteforce protection
Description
In this guide, you will learn how to install and configure Fail2Ban to protect your VPS against repeated failed authentication attempts and other malicious activity.
We are using the Linux operating system Ubuntu 24.04.
What you’ll learn
Step by step guide
1
# Step 1: Install and enable Fail2Ban2
apt install fail2ban -y3
systemctl enable --now fail2ban # autostart4
5
# Step 2: Configure Fail2Ban6
# .local is used by default. .conf is only an example file.7
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local 8
# in jail.local use this configurations: 9
# ignoreip = 127.0.0.1/8 ::1"10
# in jail.local use this configurations: bantime = 1h"11
# findtime = 10m"12
# maxretry = 3"13
# bantime.increment = true"14
# bantime.maxtime = 604800"15
# bantime.factor = 1"16
17
# Check if the sshd-jail is enabled in the .local file: 18
#[sshd]19
#enabled = true20
21
# Step 3: Reload Fail2Ban22
systemctl reload fail2ban23
systemctl restart fail2ban24
25
# Step 4: Test if Fail2Ban is working correctly26
sudo fail2ban-client -t27
28
# Step 5: Adjust the Fail2Ban log level29
cd /etc/fail2ban/30
cp fail2ban.conf fail2ban.local31
nano fail2ban.local # --> set logLevel to WARNING32
systemctl reload fail2ban33
systemctl restart fail2ban