Skip to content

fail2ban auf einem systemd System (Debian 12)

Linux
  • Ich hatte vor längerer Zeit mal das Problem ein fail2ban auf einem Debian 12 zu installieren, das kann man hier nachlesen. Damals hatte ich aufgegeben und Crowdsec installiert. Diesmal hatte ich das Problem anders herum, diesmal ging Crowdsec nicht. Also mal wieder fail2ban ausprobiert.

    Mittlerweile weiß ich, das es was mit dem Wechsel zu systemd und dem Entfernen von rsyslog zu tuen hat. Auch diesmal ging fail2ban nicht. Er meckert über nicht gefundene Logfiles. Wenn man nun das Paket rsyslog installiert, funktioniert alles. Aber.....

    Ich habe dann gesucht und gefunden, das man seit Einführung von systemd rsyslog nicht mehr benötigt. Wenn man das jetzt zusätzlich installiert, würde alles doppelt geloggt. Das wollen wir ja auch nicht 😉

    Server Infos

    root@minio:~# uname -a
    Linux minio 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux
    
    root@minio:~# cat /etc/debian_version 
    12.10
    

    Das Problem und seine Lösung

    Beim Arbeiten mit der Datei

    /etc/fail2ban/jail.local

    bin ich auf folgendes gestoßen.

    # "backend" specifies the backend used to get files modification.
    # Available options are "pyinotify", "gamin", "polling", "systemd" and "auto".
    # This option can be overridden in each jail as well.
    #
    # pyinotify: requires pyinotify (a file alteration monitor) to be installed.
    #              If pyinotify is not installed, Fail2ban will use auto.
    # gamin:     requires Gamin (a file alteration monitor) to be installed.
    #              If Gamin is not installed, Fail2ban will use auto.
    # polling:   uses a polling algorithm which does not require external libraries.
    # systemd:   uses systemd python library to access the systemd journal.
    #              Specifying "logpath" is not valid for this backend.
    #              See "journalmatch" in the jails associated filter config
    # auto:      will try to use the following backends, in order:
    #              pyinotify, gamin, polling.
    #
    # Note: if systemd backend is chosen as the default but you enable a jail
    #       for which logs are present only in its own log files, specify some other
    #       backend for that jail (e.g. polling) and provide empty value for
    #       journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200
    backend = auto
    

    Das ist jetzt die Standard Konfiguration, die nicht mit systemd läuft. Diese Standard Konfiguration lief mit rsyslog einwandfrei. Ok, kurzer Hand rsyslog deinstalliert. Den Eintrag

    backend = auto
    

    auf

    backend = systemd
    

    umgestellt.

    sshd

    Mit rsyslog stand es auf

    [sshd]
    
    # To use more aggressive sshd modes set filter parameter "mode" in jail.local:
    # normal (default), ddos, extra or aggressive (combines all).
    # See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
    # mode   = normal
    port    = ssh
    logpath = %(sshd_log)s
    backend = %(sshd_backend)s
    

    Jetzt mit systemd umgeschrieben auf

    [sshd]
    
    # To use more aggressive sshd modes set filter parameter "mode" in jail.local:
    # normal (default), ddos, extra or aggressive (combines all).
    # See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
    # mode   = normal
    port    = ssh
    # logpath = %(sshd_log)s
    # backend = %(sshd_backend)s
    backend = systemd
    

    Lief immer noch nicht 😞 Mal die AI im Netz befragt und es kam.

    apt install python3-systemd
    

    Danach neugestartet und fail2ban loggt die Bösen 🙂

     root@minio:/var/log# fail2ban-client status sshd
     Status for the jail: sshd
     |- Filter
     |  |- Currently failed: 6
     |  |- Total failed:     106
     |  `- Journal matches:  _SYSTEMD_UNIT=sshd.service + _COMM=sshd
     `- Actions
        |- Currently banned: 75
        |- Total banned:     78
        `- Banned IP list:   1.215.240.130 103.52.114.200 103.83.86.165 104.28.162.115 104.28.239.219 104.28.239.220 113.44.199.167 114.130.56.192 118.193.46.102 121.224.78.164 134.209.82.105 137.184.86.214 139.99.170.30 14.103.118.248 14.103.250.90 14.55.144.22 147.182.236.138 152.32.188.56 157.20.237.241 167.172.247.164 185.228.234.171 185.255.91.157 185.93.89.118 186.123.101.50 187.34.212.38 192.3.233.249 202.131.233.35 218.92.0.103 218.92.0.111 218.92.0.112 218.92.0.198 218.92.0.216 218.92.0.217 218.92.0.218 218.92.0.219 218.92.0.220 218.92.0.221 218.92.0.222 218.92.0.223 218.92.0.225 218.92.0.226 218.92.0.227 218.92.0.228 218.92.0.229 218.92.0.230 218.92.0.231 218.92.0.232 218.92.0.233 218.92.0.235 218.92.0.236 218.92.0.237 220.81.148.101 23.26.125.9 27.254.235.1 27.71.27.141 42.100.36.28 46.101.123.194 51.68.199.237 51.75.161.208 51.75.161.70 52.87.142.193 57.129.16.89 64.227.132.163 68.183.220.4 80.94.95.125 80.94.95.189 83.235.16.111 84.235.229.53 91.103.106.118 92.118.39.86 177.85.247.230 183.237.17.60 92.118.39.74 156.236.66.138 182.92.142.76
    

    Ok, funktioniert gut. Jetzt wollte ich das noch für das Minio-UI haben. Das sieht dann so aus.

    [minio-ui]
    enabled   = true
    backend   = auto
    port      = http,https
    filter    = minio-ui
    logpath   = /var/log/nginx/access.log
    maxretry  = 3
    findtime  = 10m
    bantime   = 1h
    

    Hier setzt man das Backend wieder auf auto und das Logfile kommt vom nginx.

    Ich hänge noch ein paar Dinge hier an, falls ich die nochmal brauche.

    Installation

    apt install fail2ban
    apt install python3-systemd
    cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    

    Konfiguration

    nano /etc/fail2ban/jail.local
    

    fail2ban-client

    fail2ban-client status sshd
    fail2ban-client status minio-ui
    fail2ban-client unban <IP-Adresse>
    

    systemd

    systemctl status fail2ban
    

    Fazit

    Wieder was gelernt. Sollte hier Blödsinn stehen, bitte ich um einen Kommentar, damit ich das anpassen oder auch löschen kann.

    Und, man kann sich auf diesem Server gar nicht mit Passwort am sshd anmelden 😁

  • Auf Debian 13 Trixie fehlt noch folgendes

    apt install python3-setuptools
    
  • AI Bots aussperren

    Linux linux block-ai nginx
    2
    0 Stimmen
    2 Beiträge
    100 Aufrufe
    FrankMF
    Wir können das noch für eine sanfte Methode erweitern, das ist die Datei robots.txt, wo man sich in alten Zeiten mal dran hielt. Einige Bots machen das, andere nicht. Praktisch, das o.g. Projekt bietet diese Datei auch an. Dann werden wir das kurz mal mit einbauen. ai-block.sh #!/bin/bash # Script um AI-Bots zu blocken # https://github.com/ai-robots-txt/ai.robots.txt/tree/main mkdir /root/AI-test cd /root/AI-test ## Daten holen curl -O https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/master/nginx-block-ai-bots.conf curl -O https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/master/robots.txt ## Daten in nginx einbauen mv nginx-block-ai-bots.conf /etc/nginx/blocklists/ mv robots.txt /var/www/html ## NGINX neustarten systemctl restart nginx.service Damit das in nginx funktioniert. Den Server Block um folgendes erweitern. # Serve robots.txt directly from Nginx location = /robots.txt { root /var/www/html; try_files $uri =404; } Kurzer Test https://<DOMAIN>/robots.txt Ergebnis User-agent: AI2Bot User-agent: Ai2Bot-Dolma User-agent: Amazonbot User-agent: anthropic-ai User-agent: Applebot User-agent: Applebot-Extended User-agent: Brightbot 1.0 User-agent: Bytespider User-agent: CCBot User-agent: ChatGPT-User User-agent: Claude-Web User-agent: ClaudeBot User-agent: cohere-ai User-agent: cohere-training-data-crawler User-agent: Crawlspace User-agent: Diffbot User-agent: DuckAssistBot User-agent: FacebookBot User-agent: FriendlyCrawler User-agent: Google-Extended User-agent: GoogleOther User-agent: GoogleOther-Image User-agent: GoogleOther-Video User-agent: GPTBot User-agent: iaskspider/2.0 User-agent: ICC-Crawler User-agent: ImagesiftBot User-agent: img2dataset User-agent: imgproxy User-agent: ISSCyberRiskCrawler User-agent: Kangaroo Bot User-agent: Meta-ExternalAgent User-agent: Meta-ExternalFetcher User-agent: OAI-SearchBot User-agent: omgili User-agent: omgilibot User-agent: PanguBot User-agent: Perplexity-User User-agent: PerplexityBot User-agent: PetalBot User-agent: Scrapy User-agent: SemrushBot-OCOB User-agent: SemrushBot-SWA User-agent: Sidetrade indexer bot User-agent: Timpibot User-agent: VelenPublicWebCrawler User-agent: Webzio-Extended User-agent: YouBot Disallow: /
  • duf - ein hübsches Kommandozeilen Tool

    Linux linux duf
    1
    1
    0 Stimmen
    1 Beiträge
    171 Aufrufe
    Niemand hat geantwortet
  • Rest-Server Version 0.12.1 released

    Linux rest-server restic linux
    1
    0 Stimmen
    1 Beiträge
    118 Aufrufe
    Niemand hat geantwortet
  • NAS 2023 - Thema Datensicherung

    Verschoben Linux proxmox linux
    2
    2
    0 Stimmen
    2 Beiträge
    186 Aufrufe
    FrankMF
    Bleibt noch etwas wichtiges. Die ganzen Konfigurationsdateien vom Proxmox Host. Sinnvoll, das man sich das sichert. #!/bin/bash # Script um mit Restic Daten automatisiert zu sichern! # Dient zum Sichern des Ordners /etc/pve! # Was soll gesichert werden? backup_pfad=/etc/pve # Programm Start restic --password-file /root/passwd -r /mnt/pve/Restic_Backups/pve backup $backup_pfad > backup_pve_001.log restic --password-file /root/passwd -r /mnt/pve/Restic_Backups/pve forget --keep-last 3 --keep-monthly 3 --prune >> backup_pve_002.log # Testen restic --password-file /root/passwd -r /mnt/pve/Restic_Backups/pve check --read-data >> backup_pve_003.log Crontab eingerichtet - fertig!
  • Mainline 5.12.x

    Images linux rockpro64
    2
    0 Stimmen
    2 Beiträge
    364 Aufrufe
    FrankMF
    5.12.0-1149-ayufan released ayufan: defconfig: add MT76x* drivers
  • Bitwarden_RS auf einem Debian Buster 10 Server installieren!

    Angeheftet Linux nginx bitwardenrs linux
    85
    14
    1 Stimmen
    85 Beiträge
    7k Aufrufe
    N
    Immer wieder gerne. Dieses mal gab es richtig etwas zu tun: 13 files changed, 137 insertions(+), 96 deletions(-) Und das nur, damit es überhaupt wieder baut. Danach folgten noch 5 Bugfixing Runden, wobei zwei davon (lediglich) das Packaging betrafen. Ergänzend noch ein Hinweis: Port 3012 für die Websocket Verbindungen ist jetzt offiziell deprecated und wird demnächst vollständig aus Vaultwarden entfernt. Genau jetzt wäre der richtige Zeitpunkt die Apache/Nginx Konfiguration dahingehend anzupassen. Hierfür habe ich neue Templates online gestellt. Apache: https://bitwarden-deb.tech-network.de/Apache-VirtualHost.example.conf Nginx: https://bitwarden-deb.tech-network.de/Nginx-VirtualHost.example.conf Schönen Sonntag!
  • NanoPi R2S - OpenWRT VLAN

    Verschoben NanoPi R2S nanopir2s openwrt linux
    11
    8
    0 Stimmen
    11 Beiträge
    2k Aufrufe
    FrankMF
    @thrakath1980 Ok, du meinst die FriendlyArm Variante von OpenWRT. Ich denke, da sollte man besser alles neu machen. Leider ist das bei OpenWRT nicht so einfach zu updaten/upgraden wie z.B. bei einem Linux Kernel. Ich habe es mal runtergeladen, wenn ich mal Zeit habe, schau ich mal rein.
  • NodeBB auf dem Raspberry3 B+ installieren

    RaspberryPi nodebb raspberrypi linux
    1
    0 Stimmen
    1 Beiträge
    869 Aufrufe
    Niemand hat geantwortet