Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
So, I have a site hosted on one of the droplets. I have been getting a lot of failed login attempts to my droplet even though I have kept the IP hidden by using CloudFlare and using proxified connections only.
By following your tutorial step-by-step, I have managed to enable fail2ban service successfully but the problem is that I made changes in the .local file that we created in the post. The changes are not reflected somehow when I tried to login through an IP. Do we have to mention somehow how to use the updated configuration file for fail2ban?
On some installations, fail2ban don’t recognize systemd logs and it fails to start with error “have not found any log file for sshd jail”. In that way, it’s wise to force backend=systemd on [sshd] section.
A very useful addition to protect against self banning is to putting in a list of IP ranges that cover expected client & admin source addresses into the ignoreip parameter in the jail.conf file. While not foolproof in preventing self bans or cases where bad traffic is originating from the same range as a valid client it many cases this is not so & you avoid getting panicked “I can’t get in” messages outside of office hours.
Thanks for the great tutorial! Unfortunately after activating it, I can’t access the server from the DO Recovery Console.
I can see in the logs:
fail2ban.filter [774431]: INFO [sshd] Found 198.211.111.194
fail2ban.filter [774431]: INFO [sshd] Found 198.211.111.194
fail2ban.filter [774431]: INFO [sshd] Found 198.211.111.194
fail2ban.actions [774431]: NOTICE [sshd] Ban 198.211.111.194
Is it just a matter of adding DO IP range to the “allow list” or…?
Thanks!
Hi Alex, thank you for this tutorial. I started looking at using fail2ban a few years ago and was horrified to find that hackers were using carfully crafted login attempts targetted at F2B. F2B was actually being exploited as a new attack vector. So then I came across “knocking” which I thought was a better solution but still not great. Basically, all accesses to sshd are initially blocked at the firewall. You knock on the server door (do a couple of invalid accesses in a row) the system recognises it and allows your IP address access through the firewall to sshd (you still need to authenticate). I’ve taken this one step further by adding a knock page to my website so there is nothing scouring error logs for special sequences of events. The knock page is also password protected and comes with a single use token (you can’t try brute forcing this puppy). To make things even more interesting, if the webserver detects an intrusion attempt then the IP address that it’s comming from gets firewalled.
Perhaps a tutorial about “knocking” would be useful to some of your followers.
Thanks! I followed the tutorial. Testing from another server did not ban the IP.
Then I read on another tutorial page: “Although Fail2Ban is excellent software, it is not as beneficial when your SSH server is configured to only public key authentication, as it is impossible to log in with a password.”
As I disabled password login, the tutorial would have been void for me. Would be cool, if you could specify that more clearly.
To prevent Fail2Ban from accidentally banning yourself (especially on SSH), you can use the following methods:
You can whitelist your IP address in the Fail2Ban configuration so that it will never get banned, regardless of failed login attempts.
sudo nano /etc/fail2ban/jail.local
ignoreip option under the [sshd] section:[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
ignoreip = 127.0.0.1/8 <your_ip>
Replace <your_ip> with your actual IP address or range of addresses you want to whitelist.
You can add multiple IPs or CIDR ranges by separating them with spaces, like so:
ignoreip = 127.0.0.1/8 192.168.1.0/24 <your_ip>
sudo systemctl restart fail2ban