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
    
  • Update 1.32.7 - Security Fixes!

    Vaultwarden vaultwarden linux
    1
    0 Stimmen
    1 Beiträge
    130 Aufrufe
    Niemand hat geantwortet
  • LibreOffice Security Update

    Linux debian linux
    1
    0 Stimmen
    1 Beiträge
    129 Aufrufe
    Niemand hat geantwortet
  • Ubiquiti ER-X - DMZ

    Verschoben OpenWRT & Ubiquiti ER-X openwrt linux er-x
    1
    2
    0 Stimmen
    1 Beiträge
    289 Aufrufe
    Niemand hat geantwortet
  • Kopia - APT Repository verfügbar

    Kopia kopia linux
    1
    0 Stimmen
    1 Beiträge
    227 Aufrufe
    Niemand hat geantwortet
  • ROCKPro64 - Projekt Wireguard Server

    Verschoben ROCKPro64 linux rockpro64 wireguard
    2
    2
    0 Stimmen
    2 Beiträge
    565 Aufrufe
    FrankMF
    Hat ein wenig Nerven gekostet und der Artikel ist auch was länger geworden Viel Spaß beim Lesen und testen!
  • NodeBB - spawn npm ENOENT

    NodeBB nodebb linux
    1
    0 Stimmen
    1 Beiträge
    439 Aufrufe
    Niemand hat geantwortet
  • sign_and_send_pubkey: signing failed: agent refused operation

    Linux linux
    1
    0 Stimmen
    1 Beiträge
    837 Aufrufe
    Niemand hat geantwortet
  • Restic - Einen ROCKPro64 als Datengrab benutzen

    Verschoben Restic linux restic
    2
    1
    0 Stimmen
    2 Beiträge
    901 Aufrufe
    FrankMF
    So, dann mal das Ganze testen wenn man seinen Haupt-PC neu installiert hat und ein paar Daten braucht. [image: 1534692579149-img_20180819_090116_ergebnis-resized.jpg] Also, mal Restic installiert. sudo apt-get install restic Nach erfolgter Installation ein Test frank@frank-MS-7A34:~/restic$ restic version restic 0.8.3 compiled with go1.10 on linux/amd64 Geht so weit. Snapshots auflisten. restic -r sftp:rock64@IP:/home/rock64/backup snapshots Sieht dann so aus. frank@frank-MS-7A34:~$ sudo restic -r sftp:rock64@192.168.3.207:/home/rock64/backup snapshots [sudo] Passwort für frank: rock64@192.168.3.207's password: enter password for repository: password is correct ID Date Host Tags Directory ---------------------------------------------------------------------- 7e2eddcb 2018-08-18 10:10:40 frank-MS-7A34 /home/frank/Bilder 073b7cb4 2018-08-18 14:21:17 frank-MS-7A34 /home/frank 6bc9b21b 2018-08-18 16:11:19 frank-MS-7A34 /home/frank ---------------------------------------------------------------------- 3 snapshots Snapshot wiederherstellen sudo restic -r sftp:rock64@IP:/home/rock64/backup restore latest --target /tmp/backup Hiermit stellen wir das Backup im temporären Ordner /tmp/backup wieder her. Hat ewig gedauert, aber ging !?!?!?