52 lines
2.6 KiB
Bash
Executable File
52 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# check-sshd-ldap.sh <username> [server]
|
|
#
|
|
# Diagnose der Kette authentik-LDAP-Outpost → SSSD → NSS/PAM → sshd.
|
|
set -uo pipefail
|
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
USER_NAME="${1:-}"
|
|
SERVER="${2:-H1}"
|
|
[[ -n "$USER_NAME" ]] || { echo "Verwendung: $(basename "$0") <username> [server]" >&2; exit 1; }
|
|
|
|
fail=0
|
|
check() { # check "Beschreibung" befehl...
|
|
local desc="$1"; shift
|
|
if "$@" >/dev/null 2>&1; then printf '✅ %s\n' "$desc"; else printf '❌ %s\n' "$desc"; fail=1; fi
|
|
}
|
|
|
|
check "sssd läuft" systemctl is-active --quiet sssd
|
|
check "sssd.conf: Rechte 0600 root" test "$(stat -c '%a %u' /etc/sssd/sssd.conf)" = "600 0"
|
|
check "sshd-Konfiguration gültig" sshd -t
|
|
check "sshd: AuthorizedKeysCommand gesetzt" bash -c "sshd -T | grep -qi '^authorizedkeyscommand .*sss_ssh_authorizedkeys'"
|
|
check "NSS: passwd enthält sss" bash -c "grep -Eq '^passwd:.*\bsss\b' /etc/nsswitch.conf"
|
|
check "User '$USER_NAME' per NSS auflösbar" getent passwd "$USER_NAME"
|
|
check "Gruppe server_${SERVER}_ssh_access" bash -c "id -nG '$USER_NAME' | tr ' ' '\n' | grep -qx 'server_${SERVER}_ssh_access'"
|
|
check "Gruppe server_${SERVER}_docker_compose" bash -c "id -nG '$USER_NAME' | tr ' ' '\n' | grep -qx 'server_${SERVER}_docker_compose'"
|
|
check "SSH-Keys-Abfrage funktioniert (Aufruf)" sss_ssh_authorizedkeys "$USER_NAME"
|
|
|
|
echo
|
|
echo "── getent passwd $USER_NAME"; getent passwd "$USER_NAME" || true
|
|
echo "── id $USER_NAME"; id "$USER_NAME" 2>&1 || true
|
|
if command -v sssctl >/dev/null; then
|
|
echo "── sssctl domain-status authentik"; sssctl domain-status authentik 2>&1 | head -n 15 || true
|
|
else
|
|
echo "── sssctl fehlt (apt install sssd-tools)"
|
|
fi
|
|
|
|
# Direkte LDAP-Abfrage mit den Daten aus sssd.conf: trennt Outpost-/Bind-Probleme von SSSD-Problemen
|
|
conf() { sed -n "s/^$1 *= *//p" /etc/sssd/sssd.conf 2>/dev/null | head -n 1; } # Wert darf selbst '=' enthalten (DN, Passwort)
|
|
if command -v ldapsearch >/dev/null && [[ -r /etc/sssd/sssd.conf ]]; then
|
|
echo "── ldapsearch (cn=$USER_NAME)"
|
|
LDAPTLS_CACERT="$(conf ldap_tls_cacert)" ldapsearch -LLL -H "$(conf ldap_uri)" -D "$(conf ldap_default_bind_dn)" \
|
|
-y <(printf %s "$(conf ldap_default_authtok)") -b "$(conf ldap_search_base)" \
|
|
"(cn=$USER_NAME)" dn cn memberOf homeDirectory 2>&1 | head -n 20 || true
|
|
fi
|
|
echo "── sssd-Log (letzte Zeilen)"; journalctl -u sssd -n 15 --no-pager 2>&1 | tail -n 15 || true
|
|
|
|
if [[ $fail -ne 0 ]]; then
|
|
echo
|
|
echo "Hinweis: Debug mit 'sssctl debug-level 6' und 'journalctl -u sssd -u ssh -f'."
|
|
fi
|
|
exit "$fail"
|