{"id":1139,"date":"2026-11-21T13:00:00","date_gmt":"2026-11-21T13:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1139"},"modified":"2026-11-21T13:00:00","modified_gmt":"2026-11-21T13:00:00","slug":"install-fail2ban-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/21\/install-fail2ban-rocky-linux-8\/","title":{"rendered":"How to Install Fail2Ban on Rocky Linux 8 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install Fail2Ban on Rocky Linux 8 to watch failed SSH authentication and place temporary source blocks in firewalld. In roughly ten minutes, you will have an SSH jail that starts at boot, reads the systemd journal, and gives you clear ban counters to review.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>A Rocky Linux 8 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 normal account that can run commands with <code>sudo<\/code>.<\/li>\n\n\n<li>A running <code>sshd<\/code> service and firewalld. Rocky Linux 8 uses DNF and the EL8 <code>powertools<\/code> repository name.<\/li>\n\n\n<li>No domain is needed because this guide protects SSH rather than a web application.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a Rocky Linux server with root or sudo access.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The commands use <code>sudo<\/code> for a regular account. Remove <code>sudo<\/code> when you are logged in as <code>root<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm Rocky Linux 8 and protect your SSH session<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the release and firewall before installing the jail so you do not attach Fail2Ban to a stopped or unexpected firewall.<\/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\nsudo firewall-cmd --list-services<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release should report version 8, <code>sshd<\/code> and firewalld should be active, and the active zone should list <code>ssh<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Rocky Linux 8.x (Green Obsidian)\"\nVERSION_ID=\"8.x\"\nID_LIKE=\"rhel centos fedora\"\nactive\nactive\npublic\n  interfaces: eth0\nssh dhcpv6-client<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>ssh<\/code> is missing from the service list, allow it before continuing. Use the active zone shown by the previous command; <code>public<\/code> is only an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --permanent --add-service=ssh\nsudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If firewalld is stopped, use the VPS console or another confirmed recovery path before starting it over SSH. Then run <code>sudo systemctl enable --now firewalld<\/code> and confirm that the active zone still permits SSH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Enable Rocky Linux 8 repositories<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2Ban is delivered through EPEL, and some EPEL dependencies come from Rocky Linux 8&#8217;s disabled-by-default PowerTools repository. Rocky calls the equivalent repository <code>CRB<\/code> on newer major releases, but the EL8 command is <code>powertools<\/code>; see the <a href=\"https:\/\/docs.rockylinux.org\/teams\/rel_eng\/repo\/\" target=\"_blank\" rel=\"noopener\">Rocky Linux repository documentation<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the DNF repository 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 finish without a repository error. <code>epel-release<\/code> is available from Rocky&#8217;s Extras repository and installs the EPEL repository definition; do not download a random RPM from a third-party mirror.<\/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 files and systemd journal support, which keeps this setup aligned with Rocky Linux 8&#8217;s service and logging stack.<\/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 depends on the current EPEL 8 build. A successful version check looks similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Fail2Ban v1.0.2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>fail2ban-firewalld<\/code> package provides the firewall action definitions, while <code>fail2ban-systemd<\/code> lets a jail read authentication events from <code>journald<\/code>. The <a href=\"https:\/\/packages.fedoraproject.org\/pkgs\/fail2ban\/fail2ban\/epel-8.html\" target=\"_blank\" rel=\"noopener\">EPEL Fail2Ban package listing<\/a> shows the Rocky-compatible EL8 package and its companion components.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Create a local SSH jail<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Store your changes in <code>jail.d<\/code> so package updates do not overwrite your policy; Fail2Ban&#8217;s <a href=\"https:\/\/github.com\/fail2ban\/fail2ban\/blob\/1.0.2\/man\/jail.conf.5\" target=\"_blank\" rel=\"noopener\">jail configuration reference<\/a> recommends local overrides instead of editing the vendor defaults.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a policy that ignores loopback, counts five failures in ten minutes, and bans 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\n\n[sshd]\nenabled = true\nfilter = sshd\nport = ssh\nEOF<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>fail2ban-firewalld<\/code> package supplies the firewalld action used by the installed configuration. If you administer the server from a fixed public address, add that address to <code>ignoreip<\/code> before starting the service, for example <code>ignoreip = 127.0.0.1\/8 ::1 203.0.113.25<\/code>. Keep the allowlist narrow so it cannot become a back door.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Leave <code>port = ssh<\/code> when SSH uses the standard service definition. For a custom port, replace it with the numeric value <code>SSH_PORT<\/code> and make sure firewalld already allows that port:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --permanent --add-port=SSH_PORT\/tcp\nsudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>SSH_PORT<\/code> with the numeric port configured in <code>\/etc\/ssh\/sshd_config<\/code> before running those commands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>sshd<\/code> filter still reads the journal; the port setting tells the ban action which traffic to block.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Validate and enable the service<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Parse the full configuration before starting Fail2Ban, then enable it immediately and at every future boot.<\/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 configuration test and service check should look like this:<\/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 contain <code>Active: active (running)<\/code>. If the parser reports an error, correct <code>\/etc\/fail2ban\/jail.d\/sshd.local<\/code> before restarting. A running daemon without a loaded <code>sshd<\/code> jail does not protect the SSH service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the SSH jail<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm the loaded jail, inspect its counters, and check the journal without intentionally generating failed logins from your own workstation.<\/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\nsudo systemctl is-enabled fail2ban<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a new VPS, zero failures and an empty rich-rule list are normal. The useful result is one loaded jail named <code>sshd<\/code>, a running service, and counters that can be read without 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 firewall rule appears only after an address reaches <code>maxretry<\/code>, while <code>enabled<\/code> confirms the daemon will return after a reboot.<\/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\">Harden 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\">Start with a Rocky Linux VPS and protect its SSH service with Fail2Ban from the first login.<\/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>No match for argument: fail2ban<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">DNF cannot see EPEL, or PowerTools was not enabled before dependency resolution. Check the repository state and rebuild the metadata cache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf repolist --enabled\nsudo dnf config-manager --set-enabled powertools\nsudo dnf install -y epel-release\nsudo dnf clean all\nsudo dnf makecache\nsudo dnf install -y fail2ban fail2ban-firewalld fail2ban-systemd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The enabled list should contain both <code>powertools<\/code> and an EPEL repository. If the server is pinned to an old Rocky minor release, update the Rocky repository configuration before retrying.<\/p>\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\">Fail2Ban cannot add or remove a ban while firewalld is stopped. Confirm SSH access through the provider console or a second session, then run <code>sudo systemctl enable --now firewalld<\/code>, verify <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 override was saved under the wrong path, or its section header was misspelled. Display 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 must contain an exact <code>[sshd]<\/code> section and <code>enabled = true<\/code>. Fix the syntax, then run <code>sudo systemctl restart fail2ban<\/code> and check <code>sudo fail2ban-client status<\/code> again.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The jail is active but records no SSH failures<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The systemd integration may be missing, or the SSH events may not be present in the journal. Check the service name and recent entries, reinstall the integration, and reload the jail:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo journalctl -u sshd -n 30 --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\">Keep <code>backend = systemd<\/code> in the local file. If <code>journalctl -u sshd<\/code> has no entries, resolve the SSH service or logging problem before changing the Fail2Ban filter.<\/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 turn off password authentication only after opening a second, verified key-based session.<\/li>\n\n\n<li>Restrict the SSH service in firewalld to your office or VPN source when that network has a stable address.<\/li>\n\n\n<li>Review <code>sudo fail2ban-client status sshd<\/code> during maintenance and keep <code>ignoreip<\/code> limited to addresses you control.<\/li>\n\n\n<li>The <a href=\"https:\/\/vpslake.com\/sshd-hardening-generator\">VPSLake SSH hardening generator<\/a> can create 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\">Is Fail2Ban included in Rocky Linux 8&#8217;s default repositories?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Rocky Linux 8 provides the base system repositories, while Fail2Ban is available through EPEL. PowerTools supplies dependencies that some EPEL packages need, so enable it before installing the daemon.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does this configuration use <code>\/var\/log\/secure<\/code>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The jail explicitly uses the <code>systemd<\/code> backend, which reads the journal associated with <code>sshd.service<\/code>. This avoids guessing a file path and matches the service-based logging used by a normal Rocky Linux 8 installation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I change the ban duration or threshold?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Edit <code>bantime<\/code>, <code>findtime<\/code>, or <code>maxretry<\/code> in <code>\/etc\/fail2ban\/jail.d\/sshd.local<\/code>. Values such as <code>30m<\/code>, <code>1h<\/code>, and <code>1d<\/code> are easier to review than raw seconds; run <code>sudo fail2ban-client -t<\/code> and restart Fail2Ban after editing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I unban an administrator&#8217;s IP address?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First add the trusted address to <code>ignoreip<\/code>, otherwise the next matching failures can ban it again. Then 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<\/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 update the local jail and run the unban command from the server.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Is Fail2Ban included in Rocky Linux 8's default repositories?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Rocky Linux 8 provides the base system repositories, while Fail2Ban is available through EPEL. PowerTools supplies dependencies that some EPEL packages need, so enable it before installing the daemon.\"}}, {\"@type\": \"Question\", \"name\": \"Does this configuration use `\/var\/log\/secure`?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. The jail explicitly uses the `systemd` backend, which reads the journal associated with `sshd.service`. This avoids guessing a file path and matches the service-based logging used by a normal Rocky Linux 8 installation.\"}}, {\"@type\": \"Question\", \"name\": \"How do I change the ban duration or threshold?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Edit `bantime`, `findtime`, or `maxretry` in `\/etc\/fail2ban\/jail.d\/sshd.local`. Values such as `30m`, `1h`, and `1d` are easier to review than raw seconds; run `sudo fail2ban-client -t` and restart Fail2Ban after editing.\"}}, {\"@type\": \"Question\", \"name\": \"How do I unban an administrator's IP address?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"First add the trusted address to `ignoreip`, otherwise the next matching failures can ban it again. Then replace `ADMIN_IP` with the affected address: If you cannot reconnect, use the VPS control panel's VNC console to update the local jail and run the unban command from the server.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install Fail2Ban on Rocky Linux 8 with EPEL, firewalld, and a systemd SSH jail. Verify protection, avoid lockouts, and fix common errors on your VPS.","protected":false},"author":1,"featured_media":1140,"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":[141,143,105,142],"class_list":["post-1139","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-server-security","tag-fail2ban","tag-firewalld","tag-rocky-linux-8","tag-ssh-security","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1139","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=1139"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1139\/revisions"}],"predecessor-version":[{"id":4143,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1139\/revisions\/4143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1140"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}