PAM (Pluggable Authentication Modules) ist das Standard-Framework für Authentifizierung unter Linux. Es ermöglicht flexible Konfiguration von Login, Passwort-Policies und Zugriffskontrolle.

Grundlagen

Konfigurationsdateien

# Service-spezifische Configs
/etc/pam.d/

# Einzelne Services
/etc/pam.d/sshd
/etc/pam.d/sudo
/etc/pam.d/login
/etc/pam.d/common-auth     # Debian
/etc/pam.d/system-auth     # RHEL

PAM-Module

# Standard-Pfad
/lib/x86_64-linux-gnu/security/  # Debian
/lib64/security/                  # RHEL

Konfigurationsformat

Syntax

# TYPE  CONTROL  MODULE  [ARGUMENTS]
auth    required pam_unix.so nullok

Typen

| Typ | Beschreibung | |-----|--------------| | auth | Authentifizierung (Passwort prüfen) | | account | Account-Verwaltung (Zugriff erlaubt?) | | password | Passwort-Änderung | | session | Session-Setup/-Teardown |

Control-Flags

| Flag | Beschreibung | |------|--------------| | required | Muss erfolgreich sein, Fehler später gemeldet | | requisite | Muss erfolgreich sein, sofortiger Abbruch | | sufficient | Bei Erfolg sofort OK (wenn vorher kein required failed) | | optional | Fehler wird ignoriert | | include | Andere Datei einbinden | | substack | Unterstack einbinden |

Standard-Konfigurationen

/etc/pam.d/common-auth (Debian)

# Standard Unix-Authentifizierung
auth    [success=1 default=ignore]  pam_unix.so nullok
auth    requisite                   pam_deny.so
auth    required                    pam_permit.so

/etc/pam.d/sshd

# SSH-Authentifizierung
@include common-auth
account required        pam_nologin.so
@include common-account
session required        pam_loginuid.so
session optional        pam_keyinit.so force revoke
@include common-session
@include common-password

Passwort-Policies

pam_pwquality

# /etc/pam.d/common-password
password    requisite   pam_pwquality.so retry=3 minlen=12 difok=3 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1

# Optionen:
# minlen=12     Mindestlänge
# difok=3       Mindestens 3 verschiedene Zeichen
# ucredit=-1    Mindestens 1 Großbuchstabe
# lcredit=-1    Mindestens 1 Kleinbuchstabe
# dcredit=-1    Mindestens 1 Ziffer
# ocredit=-1    Mindestens 1 Sonderzeichen
# retry=3       3 Versuche

Konfigurationsdatei

# /etc/security/pwquality.conf

minlen = 12
minclass = 3
maxrepeat = 3
maxclassrepeat = 4
lcredit = -1
ucredit = -1
dcredit = -1
ocredit = -1
dictcheck = 1
enforcing = 1

pam_cracklib (älter)

password    requisite   pam_cracklib.so retry=3 minlen=12 difok=3 reject_username

Account-Lockout

pam_faillock

# /etc/pam.d/common-auth (vor pam_unix)
auth    required    pam_faillock.so preauth silent deny=5 unlock_time=900 fail_interval=900
auth    [success=1 default=ignore] pam_unix.so nullok
auth    [default=die] pam_faillock.so authfail deny=5 unlock_time=900
auth    sufficient  pam_faillock.so authsucc deny=5 unlock_time=900

# Optionen:
# deny=5          Nach 5 Fehlversuchen sperren
# unlock_time=900 Nach 15 Minuten entsperren
# fail_interval=900  Zeitfenster für Fehlversuche

Konfigurationsdatei

# /etc/security/faillock.conf

deny = 5
unlock_time = 900
fail_interval = 900
audit
silent

Benutzer entsperren

# Status prüfen
faillock --user username

# Entsperren
faillock --user username --reset

Zeitbasierte Zugriffskontrolle

pam_time

# /etc/pam.d/sshd
account required pam_time.so

# /etc/security/time.conf
# service;ttys;users;times

# SSH nur werktags 8-18 Uhr
sshd;*;*;Wk0800-1800

# Login für user1 immer, user2 nur werktags
login;*;user1;Al0000-2400
login;*;user2;Wk0800-1800

# Syntax:
# Al = Alle Tage
# Wk = Werktage (Mo-Fr)
# Wd = Wochenende
# Mo,Tu,We,Th,Fr,Sa,Su = Einzelne Tage

Ressourcen-Limits

pam_limits

# /etc/pam.d/common-session
session required pam_limits.so

# /etc/security/limits.conf
# <domain> <type> <item> <value>

# Maximale Prozesse
*               soft    nproc           4096
*               hard    nproc           8192

# Maximale offene Dateien
*               soft    nofile          65536
*               hard    nofile          65536

# Maximaler Speicher
@developers     hard    as              4000000

# Core-Dumps deaktivieren
*               hard    core            0

Limits-Verzeichnis

# /etc/security/limits.d/
# Beispiel: /etc/security/limits.d/90-nproc.conf

*          soft    nproc     4096
root       soft    nproc     unlimited

Zwei-Faktor-Authentifizierung

Google Authenticator

# Installation
apt install libpam-google-authenticator

# User-Setup
google-authenticator

# /etc/pam.d/sshd
auth required pam_google_authenticator.so

# /etc/ssh/sshd_config
ChallengeResponseAuthentication yes

TOTP mit pam_oath

# Installation
apt install libpam-oath oathtool

# /etc/pam.d/sshd
auth required pam_oath.so usersfile=/etc/users.oath window=10

# /etc/users.oath
# TYPE USER PIN SEED
HOTP/T30 user1 - 0123456789abcdef0123456789abcdef

LDAP-Authentifizierung

pam_ldap

# Installation
apt install libpam-ldapd

# /etc/pam.d/common-auth
auth sufficient pam_ldap.so
auth required   pam_unix.so nullok try_first_pass

# /etc/pam.d/common-account
account sufficient pam_ldap.so
account required   pam_unix.so

Zugriffslisten

pam_access

# /etc/pam.d/sshd
account required pam_access.so

# /etc/security/access.conf
# permission : users : origins

# Root nur von localhost
-:root:ALL EXCEPT LOCAL

# Admins von überall
+:@admins:ALL

# User nur aus internem Netz
+:@users:192.168.1.0/24
-:@users:ALL

# Alle anderen verbieten
-:ALL:ALL

Gruppenbasierte Zugriffskontrolle

pam_wheel

# /etc/pam.d/su
auth required pam_wheel.so

# Nur Mitglieder der wheel-Gruppe können su verwenden
# Gruppe muss existieren und User hinzugefügt werden
groupadd wheel
usermod -aG wheel username

Session-Logging

pam_tty_audit

# /etc/pam.d/sshd
session required pam_tty_audit.so enable=*

# Alle Tastatureingaben werden in audit.log protokolliert

Debugging

Debug-Modus

# Modul mit debug
auth required pam_unix.so debug

# Logs prüfen
tail -f /var/log/auth.log
journalctl -f

pamtester

# Installation
apt install pamtester

# Test
pamtester sshd username authenticate

Zusammenfassung

| Modul | Funktion | |-------|----------| | pam_unix | Standard Unix-Auth | | pam_pwquality | Passwort-Policies | | pam_faillock | Account-Lockout | | pam_limits | Ressourcen-Limits | | pam_access | Zugriffslisten | | pam_time | Zeitbasierte Kontrolle | | pam_wheel | Gruppen-Zugriff | | pam_google_authenticator | 2FA |

| Control | Verhalten | |---------|-----------| | required | Muss OK, weitermachen | | requisite | Muss OK, sonst Abbruch | | sufficient | Bei OK fertig | | optional | Ignorieren |

| Typ | Beschreibung | |-----|--------------| | auth | Authentifizierung | | account | Zugriffskontrolle | | password | Passwort-Änderung | | session | Session-Verwaltung |

Fazit

PAM ist zentral für Linux-Sicherheit. Die modulare Architektur ermöglicht flexible Policies. Passwort-Stärke und Lockout sollten konfiguriert sein. Für Compliance sind Zeit- und Zugriffskontrollen wichtig. Änderungen sollten immer getestet werden - ein Fehler kann Logins verhindern.