{"id":1135,"date":"2026-11-21T03:00:00","date_gmt":"2026-11-21T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1135"},"modified":"2026-11-21T03:00:00","modified_gmt":"2026-11-21T03:00:00","slug":"install-fail2ban-almalinux-8","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/21\/install-fail2ban-almalinux-8\/","title":{"rendered":"How to Install Fail2Ban on AlmaLinux 8 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install Fail2Ban on AlmaLinux 8 to detect repeated SSH authentication failures and ask firewalld to block abusive addresses. In about ten minutes, you will have a boot-persistent SSH jail that reads the systemd journal and reports its ban activity.<\/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 8 server 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 reachable <code>sshd<\/code> service and firewalld; this guide uses AlmaLinux&#8217;s DNF and firewalld stack.<\/li>\n\n\n<li>No domain is necessary because the protected service is SSH.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> with root access if you need a server for this setup.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The commands below use <code>sudo<\/code>. Remove it when you are already connected as <code>root<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm the release and firewall zone<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the operating system and active firewall before installing anything, because Fail2Ban must attach its bans to the zone handling your network interface.<\/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 firewall-cmd --state\nsudo firewall-cmd --get-active-zones<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see AlmaLinux 8, an <code>active<\/code> SSH service, <code>running<\/code> firewalld, and at least one active zone. The zone name and interface vary by VPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"AlmaLinux 8.x (Sapphire Caracal)\"\nVERSION_ID=\"8.x\"\nID_LIKE=\"rhel centos fedora\"\nactive\nrunning\npublic\n  interfaces: eth0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If firewalld is missing or stopped, do not blindly enable it over a remote session. Confirm that your current provider firewall or console gives you a recovery path, then install and start it with <code>sudo dnf install -y firewalld<\/code> and <code>sudo systemctl enable --now firewalld<\/code>. Make sure the active zone still allows SSH before continuing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Enable PowerTools and EPEL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AlmaLinux 8 calls its supplemental build-dependency repository <code>powertools<\/code>; EPEL supplies Fail2Ban itself. The <a href=\"https:\/\/wiki.almalinux.org\/repos\/Extras\" target=\"_blank\" rel=\"noopener\">AlmaLinux repository guide<\/a> lists this EL8-specific repository name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the DNF repository-management plugin, enable PowerTools, 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 powertools\nsudo dnf install -y epel-release\nsudo dnf makecache<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The cache refresh should complete without a repository error. If <code>powertools<\/code> is already enabled, DNF will simply leave it unchanged.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install Fail2Ban and its AlmaLinux integrations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install the daemon along with the firewalld action definitions and systemd-journal support so the SSH filter can read the log source used by this release.<\/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 version is supplied by EPEL and may change as updates are published. A successful check looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Fail2Ban v1.1.x<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>fail2ban-firewalld<\/code> package provides actions that add and remove temporary firewalld rules. The systemd package provides the Python integration needed by <code>backend = systemd<\/code>; without it, the jail may start but fail to inspect the journal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Define an SSH jail in a local override<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Keep your policy in <code>\/etc\/fail2ban\/jail.d\/<\/code> instead of changing the vendor <code>jail.conf<\/code>, so package upgrades do not overwrite your SSH settings. Fail2Ban documents this override order in its <a href=\"https:\/\/github.com\/fail2ban\/fail2ban\/blob\/master\/man\/jail.conf.5\" target=\"_blank\" rel=\"noopener\">jail configuration reference<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a jail that allows five failures in ten minutes and blocks the source for one hour:<\/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 addresses are safe defaults. If you administer the VPS from a stable public address, append that address or a narrow CIDR to <code>ignoreip<\/code>, for example <code>203.0.113.25<\/code>, before starting the service. Do not add a broad range: a mistaken whitelist can make SSH protection ineffective. If SSH listens on a custom port, replace <code>port = ssh<\/code> with its numeric port and ensure that port is allowed in the active firewalld zone.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Test and start the service<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Validate the complete configuration first, then enable Fail2Ban at boot and start it now.<\/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 first and third commands should produce output 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 status view should include <code>Active: active (running)<\/code>. If the configuration test fails, fix that error before restarting; a running service is not useful if the SSH jail was rejected during startup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the SSH jail and firewalld action<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that the jail loaded, inspect its counters, and review recent daemon messages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fail2ban-client status\nsudo fail2ban-client status sshd\nsudo journalctl -u fail2ban -n 20 --no-pager\nsudo firewall-cmd --list-rich-rules<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a new server, no address may have been banned yet. The important checks are one loaded jail, <code>sshd<\/code> in the jail list, and zero or more counters rather than an error:<\/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 rich-rule list can be empty until an address reaches <code>maxretry<\/code>; that is normal. Do not create a test ban by guessing passwords from your own workstation, especially before adding its fixed address to <code>ignoreip<\/code>.<\/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 with root access and add Fail2Ban protection before exposing your services.<\/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>Failed to start firewalld.service<\/code> or <code>FirewallD is not running<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The ban action cannot change firewall rules while firewalld is stopped. Use a provider console or a second session if necessary, confirm that SSH is allowed, then run <code>sudo systemctl enable --now firewalld<\/code> and restart Fail2Ban with <code>sudo systemctl restart fail2ban<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>No journal files were found<\/code> or the SSH jail sees no failures<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The systemd backend needs the integration package and a journal containing <code>sshd<\/code> entries. Install the missing package, check the log source, and reload the jail:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y fail2ban-systemd\nsudo journalctl -u sshd -n 20 --no-pager\nsudo fail2ban-client -t\nsudo systemctl restart fail2ban<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>journalctl -u sshd<\/code> is empty, verify that SSH is actually managed by <code>sshd.service<\/code> and that the service is running before investigating Fail2Ban filters.<\/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\">Fail2Ban did not load the section, usually because the file path or header is wrong. Display the local file and rerun the parser:<\/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 must contain an exact <code>[sshd]<\/code> section with <code>enabled = true<\/code>. Correct the file, then run <code>sudo systemctl restart fail2ban<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Your administrator address is banned<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the trusted address to <code>ignoreip<\/code>, restart the service, and remove the existing ban. Replace <code>ADMIN_IP<\/code> with the affected address:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fail2ban-client set sshd unbanip ADMIN_IP\nsudo systemctl restart fail2ban<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you cannot reconnect, use the VPS control panel&#8217;s VNC console to make the <code>ignoreip<\/code> edit first.<\/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 testing a second SSH session with the key.<\/li>\n\n\n<li>Limit the SSH service in firewalld to your office or VPN source when you have a stable administration network.<\/li>\n\n\n<li>Keep the <code>ignoreip<\/code> list short and review <code>sudo fail2ban-client status sshd<\/code> during routine maintenance.<\/li>\n\n\n<li>Use the <a href=\"https:\/\/vpslake.com\/sshd-hardening-generator\">VPSLake SSH hardening generator<\/a> for a starting configuration, then review every proposed setting before applying it.<\/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 the AlmaLinux firewall?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Firewalld still defines the server&#8217;s general network policy, while Fail2Ban adds temporary source blocks after matching failed logins. You should continue to allow only the services the VPS actually needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Will the SSH jail survive a reboot?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. <code>systemctl enable --now fail2ban<\/code> starts the daemon immediately and registers it for future boots. The jail is loaded again from <code>\/etc\/fail2ban\/jail.d\/sshd.local<\/code> when the service starts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How can I change the number of login attempts?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Edit <code>maxretry<\/code> for the threshold and <code>findtime<\/code> for the window, then run <code>sudo fail2ban-client -t<\/code> and restart the service. Lower values react faster but can ban a user who repeatedly mistypes a password, so whitelist only trusted fixed addresses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I protect SSH on a nonstandard port?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Set the jail&#8217;s <code>port<\/code> to the numeric SSH port and allow that same port in the active firewalld zone. The <code>sshd<\/code> filter still reads authentication events from the journal; the port setting tells the ban action which traffic to block.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Does Fail2Ban replace the AlmaLinux firewall?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Firewalld still defines the server's general network policy, while Fail2Ban adds temporary source blocks after matching failed logins. You should continue to allow only the services the VPS actually needs.\"}}, {\"@type\": \"Question\", \"name\": \"Will the SSH jail survive a reboot?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. `systemctl enable --now fail2ban` starts the daemon immediately and registers it for future boots. The jail is loaded again from `\/etc\/fail2ban\/jail.d\/sshd.local` when the service starts.\"}}, {\"@type\": \"Question\", \"name\": \"How can I change the number of login attempts?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Edit `maxretry` for the threshold and `findtime` for the window, then run `sudo fail2ban-client -t` and restart the service. Lower values react faster but can ban a user who repeatedly mistypes a password, so whitelist only trusted fixed addresses.\"}}, {\"@type\": \"Question\", \"name\": \"Can I protect SSH on a nonstandard port?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Set the jail's `port` to the numeric SSH port and allow that same port in the active firewalld zone. The `sshd` filter still reads authentication events from the journal; the port setting tells the ban action which traffic to block.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install Fail2Ban on AlmaLinux 8 with EPEL, firewalld, and an SSH jail that reads the systemd journal. Verify bans and fix common errors on your VPS.","protected":false},"author":1,"featured_media":1136,"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":[94,141,143,142],"class_list":["post-1135","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-server-security","tag-almalinux-8","tag-fail2ban","tag-firewalld","tag-ssh-security","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1135","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=1135"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions"}],"predecessor-version":[{"id":4137,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions\/4137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1136"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}