How to Install Fail2Ban on AlmaLinux 10 (Step-by-Step)

Install Fail2Ban on AlmaLinux 10 with EPEL, firewalld, and the systemd journal, then protect SSH with a tested jail and useful fixes on your VPS.
A polished 3D shield protects a glowing SSH key beside an AlmaLinux server with a subtle orange accent on a midnight-blue background.

Install Fail2Ban on AlmaLinux 10 to watch failed SSH logins and temporarily block abusive IP addresses through firewalld. This setup takes about ten minutes and leaves you with a persistent SSH jail that reads AlmaLinux’s systemd journal.

Prerequisites

  • A fresh AlmaLinux 10 server with at least 1 GB of RAM and 5 GB of free disk space.
  • SSH access as root, or a normal user with working sudo privileges.
  • An active sshd service and firewalld; this guide does not use Ubuntu’s apt or ufw commands.
  • No domain is required because Fail2Ban protects the server’s SSH service directly.
  • A VPSLake Linux VPS if you need an AlmaLinux 10 server with administrator access.

The commands use sudo for a regular SSH user. If you are logged in as root, remove sudo from each command.

Step 1: Confirm AlmaLinux 10 and the SSH firewall state

Check the release, SSH service, and active firewalld zone first so the jail is attached to the firewall that actually handles incoming traffic.

grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' /etc/os-release
sudo systemctl is-active sshd
sudo firewall-cmd --state
sudo firewall-cmd --get-active-zones

Expected output resembles this; the interface and zone can differ on your VPS:

PRETTY_NAME="AlmaLinux 10.x (Cerulean Lion)"
VERSION_ID="10.x"
ID_LIKE="rhel centos fedora"
active
running
public
  interfaces: eth0

If sshd is not active, fix SSH access before enabling a protection rule. If firewalld is not running, start it only after confirming your provider’s console access is available in case the existing network policy needs review.

Step 2: Enable EPEL and install Fail2Ban support packages

Fail2Ban is distributed for Enterprise Linux through EPEL, while the companion packages connect it to firewalld and the systemd journal. The EPEL getting-started guide documents the EL10 release package used below.

Enable AlmaLinux’s CodeReady Builder-compatible repository and install the official EPEL 10 release package:

sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --set-enabled crb
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm
sudo dnf makecache

Install the main daemon together with firewalld actions and systemd-journal integration:

sudo dnf install -y fail2ban fail2ban-firewalld fail2ban-systemd
fail2ban-client --version

The version changes as EPEL publishes updates. A successful check looks similar to this:

Fail2Ban v1.1.0

fail2ban-firewalld prevents the common mistake of sending bans to an unrelated iptables action. fail2ban-systemd lets the SSH filter read entries from journald, which is the normal log source on AlmaLinux 10.

Step 3: Create a local SSH jail

Put your changes in a .local file under jail.d so package upgrades can replace the vendor defaults without erasing your policy. Do not edit /etc/fail2ban/jail.conf directly; the Fail2Ban jail configuration reference explains the override order.

Create an SSH-only policy with a one-hour ban after five failures in ten minutes:

sudo install -d -m 0755 /etc/fail2ban/jail.d
sudo tee /etc/fail2ban/jail.d/sshd.local >/dev/null <<'EOF'
[DEFAULT]
ignoreip = 127.0.0.1/8 ::1
bantime = 1h
findtime = 10m
maxretry = 5
backend = systemd
banaction = firewallcmd-rich-rules[actiontype=<multiport>]

[sshd]
enabled = true
port = ssh
filter = sshd
EOF

The loopback addresses are always safe to ignore. If you administer the VPS from a fixed public address, add that address or CIDR to the ignoreip line before starting the service so a mistaken password attempt cannot block your workstation. Keep port = ssh when SSH uses the standard service definition; for a custom SSH port, replace it with the actual numeric port.

Step 4: Validate the configuration and start the service

Test the complete configuration before starting Fail2Ban, then enable it so the SSH jail returns after a reboot.

sudo fail2ban-client -t
sudo systemctl enable --now fail2ban
sudo systemctl status fail2ban --no-pager

The test and service should report results like these:

OK: configuration test is successful
● fail2ban.service - Fail2Ban Service
     Active: active (running)

A successful configuration test does not mean anyone has been banned yet. It confirms that the jail, filter, backend, and firewalld action can be loaded without a syntax or dependency error.

Verify the SSH jail and firewalld action

Ask Fail2Ban which jails are loaded, inspect the SSH jail counters, and review its recent service messages:

sudo fail2ban-client status
sudo fail2ban-client status sshd
sudo journalctl -u fail2ban --since "10 minutes ago" --no-pager

On a newly configured VPS, the counters can be zero. The important values are one loaded jail, sshd in the jail list, and a running service:

Status
|- Number of jail: 1
`- Jail list: sshd

Status for the jail: sshd
|- Filter
|  |- Currently failed: 0
|  `- Total failed: 0
`- Actions
   |- Currently banned: 0
   `- Total banned: 0

Fail2Ban adds a rich rule to the active firewalld zone only when an address reaches maxretry. Inspect those rules without generating fake login failures:

sudo firewall-cmd --list-rich-rules
sudo systemctl is-enabled fail2ban

An empty rich-rule result is normal until a real ban occurs. The final command should print enabled, proving the service is configured to start at boot. Do not test by repeatedly guessing passwords from your own workstation; add your trusted address to ignoreip and use the status commands instead.

Troubleshooting

FirewallD is not running

The firewalld action cannot add or remove bans when its daemon is stopped. Confirm that the server is reachable through your provider console, then run sudo systemctl enable --now firewalld and sudo firewall-cmd --state before restarting Fail2Ban.

Unable to read the systemd journal or a missing systemd backend

The journal integration package may not be installed, or the jail may be using a file backend. Install the matching package and keep backend = systemd in sshd.local:

sudo dnf install -y fail2ban-systemd
sudo fail2ban-client -t
sudo systemctl restart fail2ban

Jail 'sshd' does not exist

Fail2Ban did not load the section, usually because the file was saved under the wrong path or the section name is misspelled. Check the file and rerun the configuration test:

sudo sed -n '1,120p' /etc/fail2ban/jail.d/sshd.local
sudo fail2ban-client -t

The file must contain the exact [sshd] header and enabled = true.

The service reports an iptables action error

An old configuration may force banaction = iptables-multiport, which conflicts with AlmaLinux’s firewalld workflow. Remove that override and use banaction = firewallcmd-rich-rules[actiontype=<multiport>], install fail2ban-firewalld, then restart Fail2Ban.

Hardening

  • Use SSH keys and disable password authentication only after opening a second verified session; Fail2Ban reduces repeated guesses but cannot repair weak credentials.
  • Restrict SSH in firewalld to your office or VPN source when your administration network has a stable address.
  • Add a fixed administrator address to ignoreip, but do not whitelist broad public ranges.
  • For a guided SSH policy, the VPSLake SSH hardening generator can produce a starting configuration to review before applying.

FAQ

Does Fail2Ban replace firewalld on AlmaLinux 10?

No. Fail2Ban reads authentication events and asks firewalld to add temporary source-address blocks. Keep the firewall configured with only the services and ports your VPS needs.

Why does the installation need EPEL?

Fail2Ban is not part of the standard AlmaLinux BaseOS package set. EPEL supplies the AlmaLinux-compatible daemon plus optional packages for firewalld actions and systemd journal input.

How long does a banned IP stay blocked?

The example uses bantime = 1h, so a ban expires after one hour unless the address is banned again. Change the value to formats such as 30m, 12h, or 1d when your traffic pattern justifies it.

How do I remove a legitimate address from the ban list?

First add the address to ignoreip and restart the service so it will not be banned again. Then remove the current ban with sudo fail2ban-client set sshd unbanip ADMIN_IP, replacing ADMIN_IP with the affected address.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

Is a Forex VPS Worth It? A Practical Decision Guide

Next Article

5 Best RdpBuyIndia Alternatives in 2026

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨