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
  • Install and enable Fail2Ban.
  • Configure ban times and retry limits.
  • Test the Fail2Ban configuration.
  • Configure the Fail2Ban log level.
Step by step guide
1# Step 1: Install and enable Fail2Ban
2apt install fail2ban -y
3systemctl enable --now fail2ban # autostart
4 
5# Step 2: Configure Fail2Ban
6# .local is used by default. .conf is only an example file.
7cp /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 = true
20 
21# Step 3: Reload Fail2Ban
22systemctl reload fail2ban
23systemctl restart fail2ban
24 
25# Step 4: Test if Fail2Ban is working correctly
26sudo fail2ban-client -t
27 
28# Step 5: Adjust the Fail2Ban log level
29cd /etc/fail2ban/
30cp fail2ban.conf fail2ban.local
31nano fail2ban.local # --> set logLevel to WARNING
32systemctl reload fail2ban
33systemctl restart fail2ban
Next steps