{"id":1137,"date":"2026-11-21T09:00:00","date_gmt":"2026-11-21T09:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1137"},"modified":"2026-11-21T09:00:00","modified_gmt":"2026-11-21T09:00:00","slug":"install-fail2ban-almalinux-9","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/21\/install-fail2ban-almalinux-9\/","title":{"rendered":"How to Install Fail2Ban on AlmaLinux 9 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install Fail2Ban on AlmaLinux 9 to detect repeated SSH authentication failures and add temporary blocks in firewalld. In about ten minutes, you will have a persistent SSH jail that reads the systemd journal and protects the management port.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>An AlmaLinux 9 VPS with at least 1 GB of RAM and 5 GB of free disk space.<\/li>\n\n\n<li>SSH access as <code>root<\/code>, or a regular account with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A running <code>sshd<\/code> service and firewalld. AlmaLinux 9 uses DNF and firewalld, not <code>apt<\/code> and UFW.<\/li>\n\n\n<li>No domain is required because this setup protects SSH directly.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need an AlmaLinux server with root access.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The commands assume a sudo-enabled user. If you are already connected as <code>root<\/code>, remove <code>sudo<\/code> from the commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Check AlmaLinux 9 and the active firewall zone<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm the release and network services first so Fail2Ban will work with the firewall and SSH daemon that are actually running.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' \/etc\/os-release\nsudo systemctl is-active sshd\nsudo systemctl is-active firewalld\nsudo firewall-cmd --get-active-zones<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release must show version 9, while the service checks should return <code>active<\/code>. The zone and interface depend on your VPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"AlmaLinux 9.x (Emerald Puma)\"\nVERSION_ID=\"9.x\"\nID_LIKE=\"rhel centos fedora\"\nactive\nactive\npublic\n  interfaces: eth0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If firewalld is stopped, do not start it blindly over SSH. Use the VPS control panel&#8217;s VNC console or confirm that SSH is allowed in the active zone first, then run <code>sudo systemctl enable --now firewalld<\/code>. A firewall change can otherwise cut off your current session.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Enable CRB and EPEL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2Ban is published for AlmaLinux 9 through EPEL, and EPEL dependencies may come from AlmaLinux&#8217;s CodeReady Builder repository, called CRB on this release.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the repository-management plugin, enable CRB, and add EPEL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y dnf-plugins-core\nsudo dnf config-manager --set-enabled crb\nsudo dnf install -y epel-release\nsudo dnf makecache<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The cache refresh should finish without a repository error. AlmaLinux&#8217;s <a href=\"https:\/\/wiki.almalinux.org\/repos\/Extras\" target=\"_blank\" rel=\"noopener\">extra repositories documentation<\/a> lists the EL9-specific <code>crb<\/code> command; do not substitute the EL8 <code>powertools<\/code> name here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install Fail2Ban integrations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install the daemon with its firewalld action definitions and systemd-journal support so the SSH filter can read AlmaLinux 9 authentication events.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y fail2ban fail2ban-firewalld fail2ban-systemd\nfail2ban-client --version<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The package version can change as EPEL publishes updates. A valid check looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Fail2Ban v1.1.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The firewalld package supplies the action that creates temporary rich rules. The systemd package supplies the journal reader used by <code>backend = systemd<\/code>. EPEL&#8217;s <a href=\"https:\/\/packages.fedoraproject.org\/pkgs\/fail2ban\/fail2ban\/epel-9.html\" target=\"_blank\" rel=\"noopener\">Fail2Ban package page<\/a> lists these EL9 package relationships.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Create an SSH jail override<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Keep local policy in <code>jail.d<\/code> so a future package update does not overwrite it; the vendor <code>jail.conf<\/code> is a defaults file, not the right place for custom settings. Fail2Ban&#8217;s <a href=\"https:\/\/github.com\/fail2ban\/fail2ban\/blob\/master\/man\/jail.conf.5\" target=\"_blank\" rel=\"noopener\">jail configuration manual<\/a> describes the override behavior.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a jail that bans an address for one hour after five failures within ten minutes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo install -d -m 0755 \/etc\/fail2ban\/jail.d\nsudo tee \/etc\/fail2ban\/jail.d\/sshd.local &gt;\/dev\/null &lt;&lt;'EOF'\n[DEFAULT]\nignoreip = 127.0.0.1\/8 ::1\nbantime = 1h\nfindtime = 10m\nmaxretry = 5\nbackend = systemd\nbanaction = firewallcmd-rich-rules[actiontype=&lt;multiport&gt;]\n\n[sshd]\nenabled = true\nfilter = sshd\nport = ssh\nEOF<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loopback entries are safe defaults. Add your fixed administrator address to <code>ignoreip<\/code> before enabling the service if you manage the VPS from a stable public IP, for example <code>ignoreip = 127.0.0.1\/8 ::1 203.0.113.25<\/code>. Use a narrow address or CIDR, not a broad public range.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Leave <code>port = ssh<\/code> when the SSH service uses its normal service definition. If SSH listens on a custom port, replace it with that numeric port and make sure the same port is already allowed in the active firewalld zone.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Validate and start the service<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Parse the complete configuration before starting Fail2Ban, then enable it for future boots and start it immediately.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fail2ban-client -t\nsudo systemctl enable --now fail2ban\nsudo systemctl is-active fail2ban\nsudo systemctl status fail2ban --no-pager -l<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The parser and service check should produce results similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>OK: configuration test is successful\nactive<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The longer status output should include <code>Active: active (running)<\/code>. If the parser reports an error, correct the jail file before restarting; a running daemon without the <code>sshd<\/code> jail does not protect SSH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the SSH jail<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the loaded jail, its counters, the Fail2Ban journal, and the firewalld rules without deliberately generating failed logins:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fail2ban-client status\nsudo fail2ban-client status sshd\nsudo journalctl -u fail2ban --since \"10 minutes ago\" --no-pager\nsudo firewall-cmd --list-rich-rules\nsudo systemctl is-enabled fail2ban<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a new VPS, the counters can all be zero and the rich-rule list can be empty. That is expected until an address reaches <code>maxretry<\/code>; the important result is that one jail is loaded and its name is <code>sshd<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Status\n|- Number of jail: 1\n`- Jail list: sshd\n\nStatus for the jail: sshd\n|- Filter\n|  |- Currently failed: 0\n|  `- Total failed: 0\n`- Actions\n   |- Currently banned: 0\n   `- Total banned: 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final command should print <code>enabled<\/code>, confirming that Fail2Ban will return after a reboot. Avoid testing by guessing passwords from your workstation; whitelist its fixed address first or inspect the counters and service logs instead.<\/p>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Get a Linux VPS\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Secure your SSH access<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Get a Linux VPS<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Deploy AlmaLinux 9 with root access and add Fail2Ban protection from the start.<\/p>\n\t<\/div>\n\t<a class=\"vl-cta-banner__button\" href=\"\/buy-vps\" aria-label=\"Get a Linux VPS\">Get a Linux VPS<\/a>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>FirewallD is not running<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The action cannot add or remove bans while firewalld is stopped. Confirm that you have console access and that SSH is allowed, then run <code>sudo systemctl enable --now firewalld<\/code>, check <code>sudo firewall-cmd --state<\/code>, and restart Fail2Ban.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Jail 'sshd' does not exist<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The local file was not loaded, often because it was saved outside <code>\/etc\/fail2ban\/jail.d\/<\/code> or the section header is misspelled. Inspect the file and run the parser again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sed -n '1,120p' \/etc\/fail2ban\/jail.d\/sshd.local\nsudo fail2ban-client -t<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The file needs an exact <code>[sshd]<\/code> section with <code>enabled = true<\/code>. Fix any syntax error, then run <code>sudo systemctl restart fail2ban<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The jail loads but shows no SSH failures<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The jail may be reading a file backend while AlmaLinux is storing SSH events in journald, or the journal integration package may be missing. Confirm the service name and journal entries, reinstall the integration, and reload the daemon:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo journalctl -u sshd -n 20 --no-pager\nsudo dnf install -y fail2ban-systemd\nsudo fail2ban-client -t\nsudo systemctl restart fail2ban<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>backend = systemd<\/code> setting and the <code>sshd<\/code> filter must remain in <code>sshd.local<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>iptables<\/code> action errors appear in the journal<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An older local override may force <code>banaction = iptables-multiport<\/code>, even though this server uses firewalld. Remove that override and keep <code>banaction = firewallcmd-rich-rules[actiontype=&lt;multiport&gt;]<\/code>, then verify that <code>fail2ban-firewalld<\/code> is installed and restart the service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hardening<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>Use SSH keys and disable password authentication only after opening a second verified key-based session.<\/li>\n\n\n<li>Restrict SSH in firewalld to your office or VPN source when you have a stable administration network.<\/li>\n\n\n<li>Review <code>sudo fail2ban-client status sshd<\/code> during maintenance and keep <code>ignoreip<\/code> limited to trusted addresses.<\/li>\n\n\n<li>The <a href=\"https:\/\/vpslake.com\/sshd-hardening-generator\">VPSLake SSH hardening generator<\/a> can provide a starting policy to review before applying.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Does Fail2Ban replace firewalld on AlmaLinux 9?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Firewalld remains the server&#8217;s general access-control layer, while Fail2Ban adds temporary source blocks after matching failed authentication events. You still need to allow only the services and ports your VPS requires.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why are both CRB and EPEL enabled?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">EPEL supplies Fail2Ban, while CRB supplies packages that EPEL software may need on AlmaLinux 9. Enabling CRB prevents dependency resolution from failing during installation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I change the ban threshold later?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Edit <code>maxretry<\/code> to change the number of failures and <code>findtime<\/code> to change the counting window, then run <code>sudo fail2ban-client -t<\/code> and restart Fail2Ban. A lower threshold reacts sooner but increases the chance of banning an administrator who mistypes credentials.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I unban my own IP address?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First add the address to <code>ignoreip<\/code> so it is not banned again. Then replace <code>ADMIN_IP<\/code> below with the affected address:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fail2ban-client set sshd unbanip ADMIN_IP<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If SSH is unreachable, use the VPS control panel&#8217;s VNC console to update the jail and run the command locally.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Does Fail2Ban replace firewalld on AlmaLinux 9?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Firewalld remains the server's general access-control layer, while Fail2Ban adds temporary source blocks after matching failed authentication events. You still need to allow only the services and ports your VPS requires.\"}}, {\"@type\": \"Question\", \"name\": \"Why are both CRB and EPEL enabled?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"EPEL supplies Fail2Ban, while CRB supplies packages that EPEL software may need on AlmaLinux 9. Enabling CRB prevents dependency resolution from failing during installation.\"}}, {\"@type\": \"Question\", \"name\": \"Can I change the ban threshold later?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Edit `maxretry` to change the number of failures and `findtime` to change the counting window, then run `sudo fail2ban-client -t` and restart Fail2Ban. A lower threshold reacts sooner but increases the chance of banning an administrator who mistypes credentials.\"}}, {\"@type\": \"Question\", \"name\": \"How do I unban my own IP address?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"First add the address to `ignoreip` so it is not banned again. Then replace `ADMIN_IP` below with the affected address: If SSH is unreachable, use the VPS control panel's VNC console to update the jail and run the command locally.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install Fail2Ban on AlmaLinux 9 with EPEL, firewalld, and an SSH jail that reads the systemd journal. Verify protection and fix common errors.","protected":false},"author":1,"featured_media":1138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[5,13],"tags":[95,141,143,142],"class_list":["post-1137","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-server-security","tag-almalinux-9","tag-fail2ban","tag-firewalld","tag-ssh-security","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/comments?post=1137"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":4142,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1137\/revisions\/4142"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1138"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}