Linux Labs

Server security / Stage 5 of 10

Password brute force and fail2ban

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 7 · lab · 30 minmedium

The brute force goes on

Someone on the neighbouring machine keeps trying to log in to the server's SSH. fail2ban is installed and running, a colleague has even tuned it, and still there is no ban. Find out why and make sure the attacker gets banned and the administrator never does.

Situation

Someone on node2 keeps trying to log in to node1's SSH: every twenty seconds there are new attempts under made-up user names. They show up in the login journal: sudo journalctl -u ssh -f. node1 has fail2ban for exactly this: the service is enabled and running, the sshd jail is started, and last week a colleague went over its settings once more. node2 has still not been banned.

The administrator's laptop admin-pc (its address: getent hosts admin-pc) logs in to node1 every day and sometimes gets the login wrong. fail2ban must not ban that address.

node1 is your terminal; reach node2 with ssh node2. sudo works without a password on both machines.

Task

  1. node2's address is banned by the sshd jail: sudo fail2ban-client status sshd lists it, and node1's SSH is closed to node2.
  2. Any other address on the network gets banned by itself after five failed SSH logins within ten minutes, with no manual commands.
  3. The jail skips failed logins from admin-pc, and that address does not get banned.
  4. The settings are saved in the /etc/fail2ban files: after sudo systemctl restart fail2ban the jail works the same. The fail2ban service is enabled.

The lab has no internet access, only the network between node1 and node2. Everything you need is installed on both machines. There is no need to stop the attacker on node2: the task is in fail2ban on node1.

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 4
  • node2's address is banned by the sshd jail — node1's SSH is closed to node2 — not done yet
  • A new address on the network gets banned by itself after five failed SSH logins — not done yet
  • The jail skips failed logins from admin-pc and does not ban it — not done yet
  • The settings are saved in /etc/fail2ban — after fail2ban restarts the jail works the same; the service is enabled — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 4
  • node2's address is banned by the sshd jail — node1's SSH is closed to node2 — not done yet
  • A new address on the network gets banned by itself after five failed SSH logins — not done yet
  • The jail skips failed logins from admin-pc and does not ban it — not done yet
  • The settings are saved in /etc/fail2ban — after fail2ban restarts the jail works the same; the service is enabled — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 4
  • node2's address is banned by the sshd jail — node1's SSH is closed to node2 — not done yet
  • A new address on the network gets banned by itself after five failed SSH logins — not done yet
  • The jail skips failed logins from admin-pc and does not ban it — not done yet
  • The settings are saved in /etc/fail2ban — after fail2ban restarts the jail works the same; the service is enabled — not done yet
Loading…