Skip to content

fail2ban auf einem systemd System (Debian 12)

Linux
2 1 266
  • 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
    
  • FrankMF FrankM hat am auf dieses Thema verwiesen
  • OpenCloud - Docker Compose Hetzner VM

    Angeheftet Verschoben OpenCloud opencloud linux docker
    2
    2
    0 Stimmen
    2 Beiträge
    259 Aufrufe
    FrankMF
    Ich habe mich nochmal mit verschiedenen Aspekten der produktiven Installation beschäftigt. Auch ein wenig die KI befragt und dann ein paar Änderungen vorgenommen. Was hatte mich gestört? Traefik lief als root. Um das zu ändern, habe ich das docker-compose.yml angepasst. Ich habe auch gleich mal auf die aktuelle Version angepasst. services: traefik: image: traefik:v3.4.1 #3.3.1 container_name: traefik user: "1000:1001" # 1000 = dockeruser, 1001=docker group cap_add: - NET_BIND_SERVICE # erlaubt Ports <1024 restart: always networks: - opencloud-net ports: - "80:80" - "443:443" volumes: - ./certs:/certs # bind-mount acme.json - /var/run/docker.sock:/var/run/docker.sock:ro command: - "--log.level=${TRAEFIK_LOG_LEVEL:-ERROR}" # Let's Encrypt HTTP-01 Challenge - "--certificatesResolvers.http.acme.email=${TRAEFIK_ACME_MAIL:-example@example.org}" - "--certificatesResolvers.http.acme.storage=/certs/acme.json" - "--certificatesResolvers.http.acme.httpChallenge.entryPoint=http" - "--certificatesResolvers.http.acme.caserver=${TRAEFIK_ACME_CASERVER:-https://acme-v02.api.letsencrypt.org/directory}" # Dashboard - "--api.dashboard=true" # Entrypoints - "--entryPoints.http.address=:80" - "--entryPoints.http.http.redirections.entryPoint.to=https" - "--entryPoints.http.http.redirections.entryPoint.scheme=https" - "--entryPoints.https.address=:443" - "--entryPoints.https.transport.respondingTimeouts.readTimeout=12h" - "--entryPoints.https.transport.respondingTimeouts.writeTimeout=12h" - "--entryPoints.https.transport.respondingTimeouts.idleTimeout=3m" # Docker Provider - "--providers.docker.endpoint=unix:///var/run/docker.sock" - "--providers.docker.exposedByDefault=false" # Access Log - "--accessLog=true" - "--accessLog.format=json" - "--accessLog.fields.headers.names.X-Request-Id=keep" labels: - "traefik.enable=${TRAEFIK_DASHBOARD:-false}" - "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_BASIC_AUTH_USERS:-admin:$$apr1$$4vqie50r$$YQAmQdtmz5n9rEALhxJ4l.}" - "traefik.http.routers.traefik.entrypoints=https" - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_DOMAIN:-traefik.opencloud.test}`)" - "traefik.http.routers.traefik.middlewares=traefik-auth" - "traefik.http.routers.traefik.tls.certresolver=http" - "traefik.http.routers.traefik.service=api@internal" networks: opencloud-net: volumes: {} Und hierzu - ./certs:/certs # bind-mount acme.json brauch es noch ein paar Anpassungen auf dem Host, also im Verzeichnis von wo wir deployen mit dem dockeruser! mkdir -p ./certs touch ./certs/acme.json chmod 600 ./certs/acme.json chown 1000:1000 ./certs/acme.json # UID muss mit docker-compose user übereinstimmen Das klappt jetzt hier einwandfrei. dockeruser@opencloud:~/opencloud/deployments/examples/opencloud_full$ docker exec -it traefik id uid=1000 gid=1001 groups=1001 Sieht soweit gut aus Die KI meint noch das hier Wenn du maximale Sicherheit willst, kannst du langfristig docker-socket-proxy einsetzen. Er erlaubt Traefik nur lesenden Zugriff auf die Container-API: → Projektseite: Tecnativa/docker-socket-proxy Das muss ich aber erst noch sacken lassen und mich etwas zu einlesen.
  • Update 1.33.0 - Security Fixes!

    Vaultwarden vaultwarden linux
    1
    0 Stimmen
    1 Beiträge
    154 Aufrufe
    Niemand hat geantwortet
  • 0 Stimmen
    2 Beiträge
    551 Aufrufe
    FrankMF
    Ich habe den Sonntag mal genutzt um ein wenig was einzubauen. Einmal habe ich mit datatables.net die Tabelle etwas funktionaler gestaltet. [image: 1736705735786-00a95363-1f41-4bbf-884a-34f21aea81e4-grafik.png] Man kann nun suchen, sortieren und wenn man mehr als 10 Datenpunkte hat, hat die Tabelle auch Pagination. Ein nettes Projekt, macht einiges einfacher Das nächste, ich hatte es im Video ja kurz erwähnt, mir fehlte ja noch die Restore Funktion von Restic. Ok, ist jetzt auch drin. Da die Benutzerverwaltung mittlerweile komplett eingebaut ist, werde ich demnächst meine Test Datenbanken und alles was damit zu tuen hat, aus dem Code entfernen. Brauch ich jetzt nicht mehr. Habe jetzt zwei Benutzer, einen Produktiven und einen zum Testen. Langfristig steht auch noch eine zweite Sprache auf dem Zettel. Aber, dafür muss ich Lust haben, das Thema juckt nicht so richtig
  • RockPro64 - Mainline Kernel 6.8.0-rc3

    ROCKPro64 rockpro64 linux mainline
    2
    0 Stimmen
    2 Beiträge
    520 Aufrufe
    FrankMF
    https://github.com/ayufan-rock64/linux-mainline-kernel/releases/tag/6.8.0-1190-ayufan
  • NodeBB - v3.3.0

    NodeBB nodebb linux
    1
    0 Stimmen
    1 Beiträge
    154 Aufrufe
    Niemand hat geantwortet
  • Cockpit

    Linux linux
    1
    1
    0 Stimmen
    1 Beiträge
    272 Aufrufe
    Niemand hat geantwortet
  • Debian 10.4 released und Wireguard kaputt :(

    Linux linux wireguard
    1
    0 Stimmen
    1 Beiträge
    287 Aufrufe
    Niemand hat geantwortet
  • NVMe Firmware - Daten werden benötigt

    Linux linux
    1
    0 Stimmen
    1 Beiträge
    757 Aufrufe
    Niemand hat geantwortet