Ceci est une ancienne révision du document !
Fail2ban pour Nextcloud sur Ubuntu22
https://docs.nextcloud.com/server/latest/admin_manual/installation/harden_server.html#setup-fail2ban
source: https://linuxize.com/post/install-configure-fail2ban-on-debian-10/
# apt-get install fail2ban
whois
pour des infos plus détaillées sur les IPs bloquées # apt-get install whois
# cp /etc/fail2ban/jail.{conf,local}
# nano /etc/fail2ban/jail.local ... ignoreip = 127.0.0.1/8 IPs.reseau.lan.local/24 si besoin ... bantime = 60m ... findtime = 10m ... maxretry = 5 ... destemail = admin@domain.tld ... action = %(action_mw)s ... # systemctl restart fail2ban
Activer les jails:
Le plus simple est de faire ça dans webmin. Activer toutes les jails apache et SSL.
Également dans
# nano /etc/fail2ban/jail.local ---- [sshd] ... enabled = true
Malheureusement les jails de fail2ban ne suffisent pas car ce n'est pas Apache qui logge pas les tentatives d'identification mais Nextcloud!
# nano /etc/fail2ban/filter.d/nextcloud.conf [Definition] _groupsre = (?:(?:,?\s*"\w+":(?:"[^"]+"|\w+))*) failregex = ^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Login failed: ^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Trusted domain error. datepattern = ,?\s*"time"\s*:\s*"%%Y-%%m-%%d[T ]%%H:%%M:%%S(%%z)?"
# nano /etc/fail2ban/jail.d/nextcloud.local [nextcloud] backend = auto enabled = true port = 80,443 protocol = tcp filter = nextcloud logpath = /var/www/nextcloud-data/nextcloud.log
# systemctl restart fail2ban
# nano /etc/apache2/sites-available/joomla.conf et ajouter: <Directory /var/www/joomla/administrator> Order Deny,Allow Deny from all Allow from ip1.ou.bien.réseau1/24 ip2.ou.bien.réseau.2/24 </Directory>
# systemctl restart apache2