How to Fix “ERROR Found no accessible config files for fail2ban under /etc/fail2ban” in Ubuntu


2 views

After completely removing fail2ban (including config files) with:

sudo apt-get remove fail2ban
sudo apt-get purge fail2ban
sudo rm -r /etc/fail2ban

The package fails to recreate its default configuration files during reinstallation, leaving the service non-functional.

Normally, when you install fail2ban via apt, it should create:

  • /etc/fail2ban/fail2ban.conf
  • /etc/fail2ban/jail.conf
  • /etc/fail2ban/jail.d/*
  • /etc/fail2ban/filter.d/*

However, in some Ubuntu/Debian versions, the package maintainer scripts might fail to properly regenerate these files if the directory structure was manually removed.

Here's the proper way to reset fail2ban completely:

# Full removal
sudo apt-get remove --purge fail2ban
sudo rm -rf /etc/fail2ban

# Clean up any remaining dependencies
sudo apt-get autoremove

# Reinstall with forced configuration
sudo apt-get install --reinstall -o Dpkg::Options::="--force-confask,confnew,confmiss" fail2ban

If the above doesn't work, you can manually restore the config files:

# First create the directory structure
sudo mkdir -p /etc/fail2ban/{jail.d,filter.d,action.d}

# Then download default configs
sudo wget -O /etc/fail2ban/fail2ban.conf https://raw.githubusercontent.com/fail2ban/fail2ban/master/config/fail2ban.conf
sudo wget -O /etc/fail2ban/jail.conf https://raw.githubusercontent.com/fail2ban/fail2ban/master/config/jail.conf

# Set proper permissions
sudo chown -R root:root /etc/fail2ban
sudo chmod -R 644 /etc/fail2ban
sudo chmod 755 /etc/fail2ban

# Restart the service
sudo systemctl restart fail2ban

After restoration, verify with:

# Check config files
ls -la /etc/fail2ban

# Check service status
sudo fail2ban-client status

# Test configuration
sudo fail2ban-client -t

For safer configuration management:

# Always work with local copies
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local

# Then modify these .local files instead

When attempting to clean reinstall fail2ban on Ubuntu 14.04.2 LTS after configuration issues, you might encounter this situation:

apt-get remove fail2ban
apt-get purge fail2ban
rm -r /etc/fail2ban

Then after reinstalling, the service fails with these errors:

ERROR  Found no accessible config files for 'fail2ban' under /etc/fail2ban
ERROR  No section: 'Definition'
ERROR  Found no accessible config files for 'jail' under /etc/fail2ban

The critical issue stems from the package manager's behavior. While apt-get purge removes configuration files, manually deleting /etc/fail2ban prevents the package from restoring default configs during reinstallation.

Step 1: Full cleanup

sudo apt-get remove --purge fail2ban
sudo rm -rf /etc/fail2ban
sudo apt-get autoremove

Step 2: Force reinstall with default configs

sudo apt-get install --reinstall -o Dpkg::Options::="--force-confnew" fail2ban

The --force-confnew option ensures fresh configuration files are installed.

After successful installation, verify the configuration files exist:

ls -la /etc/fail2ban/

You should see these essential files:

  • fail2ban.conf
  • jail.conf
  • filter.d/ directory
  • action.d/ directory

If you still encounter problems, try regenerating the default configs manually:

sudo cp /usr/share/fail2ban/fail2ban.conf /etc/fail2ban/
sudo cp /usr/share/fail2ban/jail.conf /etc/fail2ban/

Instead of deleting configs, always:

  1. Backup existing configs
  2. Use version control for customizations
  3. Modify jail.local instead of jail.conf