Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash script to reset Fail2Ban - clears / truncates log file and deletes the sqlite database - stops and restarts service during this process.
# Bash Script by
# ************************************************************
# This script clears the log file and database of Fail2Ban
# This resets Fail2Ban to a completely clean state
# Useful to use after you have finished testing all your jails
# and completed your initial setup of Fail2Ban and are now
# putting the server into LIVE mode
# ************************************************************
# Please Set your log file and sqlite db locations
# Locations below are common on Ubuntu and Debian based systems
# Now let us clean up
echo "Stopping Fail2Ban Service"
sudo service fail2ban stop
echo "Truncating Fail2Ban Log File"
sudo truncate -s 0 $F2Blog
echo "Deleting Fail2Ban SQLite Database"
sudo rm $F2Bdb
echo "Restarting Fail2Ban Service"
sudo service fail2ban restart
echo "All Done"
Copy link

sudo rm $F2Bdb
the database has been locked, we fix it using
sudo rm -rf $F2Bdb

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment