Die PAM-Konfiguration für den SSH-Dienst (sshd) ist typischerweise sehr schlank und nutzt include-Direktiven, um zentrale Authentifizierungsregeln wiederzuverwenden. Diese Seite erklärt den Aufbau am Beispiel einer Standard-SSHD-Konfiguration.
#%PAM-1.0 auth include system-remote-login account include system-remote-login password include system-remote-login session include system-remote-login
q
#%PAM-1.0
| Element | Bedeutung |
|---|---|
| #%PAM-1.0 | Gibt die verwendete PAM-Version an. Dies ist eine Kommentarzeile, die die PAM-Bibliothek informiert |
| Zweck | Kompatibilitätskennzeichnung, sollte bei allen PAM-Konfigurationsdateien vorhanden sein |
Die Konfiguration definiert für jeden der vier PAM-Modultypen eine Regel:
auth include system-remote-login
| Element | Bedeutung |
|---|---|
| auth | Modultyp: Authentifizierung - prüft Benutzeridentität (Passwort, Keys, etc.) |
| include | Control Flag: Bindet eine andere PAM-Konfigurationsdatei ein |
| system-remote-login | Name der einzubindenden Konfigurationsdatei (/etc/pam.d/system-remote-login) |
account include system-remote-login
| Element | Bedeutung |
|---|---|
| account | Modultyp: Account-Management - prüft ob Zugriff erlaubt ist (z.B. Account gesperrt, Zeitbeschränkungen) |
password include system-remote-login
| Element | Bedeutung |
|---|---|
| password | Modultyp: Passwort-Management - wird bei Passwortänderungen verwendet |
session include system-remote-login
| Element | Bedeutung |
|---|---|
| session | Modultyp: Session-Management - Aktionen vor/nach Login (z.B. Logs, Home-Verzeichnis mounten) |
Das include Control Flag hat eine besondere Funktion:
Vorteil: Änderungen an system-remote-login gelten automatisch für alle Dienste, die sie einbinden (SSH, FTP, etc.)
# Datei ansehen cat /etc/pam.d/system-remote-login # Oder mit sudo falls Rechte fehlen sudo cat /etc/pam.d/system-remote-login
Arch Linux / Manjaro:
#%PAM-1.0 auth required pam_tally2.so onerr=succeed file=/var/log/tallylog auth required pam_shells.so auth required pam_nologin.so auth include system-login account required pam_tally2.so account required pam_access.so account required pam_nologin.so account include system-login password include system-login session optional pam_motd.so motd=/etc/motd session optional pam_mail.so dir=/var/spool/mail standard quiet session include system-login
Debian / Ubuntu:
#%PAM-1.0 auth required pam_env.so auth required pam_unix.so nullok auth required pam_nologin.so account required pam_unix.so account required pam_nologin.so password required pam_unix.so sha512 shadow session required pam_limits.so session required pam_unix.so session optional pam_motd.so session optional pam_lastlog.so
Red Hat / CentOS / Fedora:
#%PAM-1.0 auth required pam_sepermit.so auth include password-auth account required pam_nologin.so account include password-auth password include password-auth session optional pam_keyinit.so force revoke session include password-auth session optional pam_motd.so
Bei einem SSH-Login durchläuft PAM folgende Schritte (vereinfacht):
# SSHD PAM-Konfiguration anzeigen cat /etc/pam.d/sshd # Eingebundene Datei anzeigen cat /etc/pam.d/system-remote-login # Falls weitere includes vorhanden, diese auch anzeigen cat /etc/pam.d/system-login cat /etc/pam.d/password-auth
# PAM-Aktivitäten im Journal sudo journalctl -u sshd | grep pam # Authentifizierungs-Logs sudo tail -f /var/log/auth.log # Debian/Ubuntu sudo tail -f /var/log/secure # RHEL/CentOS # Fehlgeschlagene Login-Versuche sudo journalctl -u sshd | grep "Failed password"
Warnung: Änderungen sollten vorsichtig vorgenommen werden. Immer eine offene SSH-Session zum Testen behalten!
Beispiel: Zwei-Faktor-Authentifizierung hinzufügen
#%PAM-1.0 # Google Authenticator VOR system-remote-login auth required pam_google_authenticator.so auth include system-remote-login account include system-remote-login password include system-remote-login session include system-remote-login
Beispiel: Zusätzliche Session-Logs
#%PAM-1.0 auth include system-remote-login account include system-remote-login password include system-remote-login session include system-remote-login # Zusätzliches Logging nach includes session optional pam_exec.so /usr/local/bin/log-ssh-session.sh
# Eigene Konfiguration für alle Remote-Dienste sudo nano /etc/pam.d/my-remote-login
Inhalt von my-remote-login:
#%PAM-1.0 # Strenge Regeln für Remote-Zugriff auth required pam_faillock.so preauth deny=3 unlock_time=1800 auth required pam_unix.so auth required pam_faillock.so authfail deny=3 unlock_time=1800 account required pam_faillock.so account required pam_unix.so account required pam_time.so password required pam_pwquality.so retry=3 minlen=12 password required pam_unix.so sha512 shadow session required pam_limits.so session required pam_unix.so session optional pam_lastlog.so
Dann in /etc/pam.d/sshd:
#%PAM-1.0 auth include my-remote-login account include my-remote-login password include my-remote-login session include my-remote-login
| Distribution | Haupt-Include-Datei | Besonderheiten |
|---|---|---|
| Arch Linux | system-remote-login | Nutzt system-login als zweite Ebene |
| Debian/Ubuntu | common-auth, common-account, common-password, common-session | Mehrere separate includes pro Typ |
| RHEL/CentOS | password-auth, system-auth | password-auth für Remote, system-auth für lokal |
| SUSE | common-auth-pc | Eigenes Schema mit -pc (Pluggable Client) |
Arch Linux Beispiel:
/etc/pam.d/sshd
└── include: system-remote-login
└── include: system-login
└── required: pam_unix.so, pam_systemd.so, etc.
Debian/Ubuntu Beispiel:
/etc/pam.d/sshd
├── auth → include: common-auth
├── account → include: common-account
├── password→ include: common-password
└── session → include: common-session
# In jeder Zeile "debug" hinzufügen auth required pam_unix.so debug # Logs anzeigen sudo journalctl -u sshd -f
| Problem | Ursache | Lösung |
|---|---|---|
| SSH-Login funktioniert nicht | Tippfehler in PAM-Config | Include-Dateien prüfen, Syntax kontrollieren |
| „Permission denied“ trotz richtigem Passwort | pam_nologin aktiv | /etc/nologin entfernen oder als root einloggen |
| Alle Logins geblockt | Fehlerhafte include-Datei | Im Notfall mit init=/bin/bash booten und korrigieren |
| Key-Auth funktioniert, Passwort nicht | pam_unix.so fehlt in auth | Include-Dateien prüfen, pam_unix.so ergänzen |
# 1. Aktuelle Config sichern sudo cp /etc/pam.d/sshd /etc/pam.d/sshd.backup sudo cp /etc/pam.d/system-remote-login /etc/pam.d/system-remote-login.backup # 2. Änderungen vornehmen sudo nano /etc/pam.d/sshd # 3. SSH-Dienst neu laden (NICHT beenden!) sudo systemctl reload sshd # 4. In NEUER Session testen (alte Session OFFEN lassen!) ssh user@localhost # 5. Bei Problemen: Aus alter Session zurückrollen sudo cp /etc/pam.d/sshd.backup /etc/pam.d/sshd sudo systemctl reload sshd