scripte/ldap_beitritt.sh

108 lines
3.4 KiB
Bash

#!/bin/bash
# Schritt 1: /etc/nslcd.conf erstellen oder ersetzen
echo "Erstelle oder ersetze /etc/nslcd.conf..."
cat <<EOF > /etc/nslcd.conf
# nslcd configuration file. See nslcd.conf(5) for details.
# The user and group nslcd should run as.
uid nslcd
gid nslcd
# The location at which the LDAP server(s) should be reachable.
uri ldap://192.168.174.101:7389
# The search base that will be used for all queries.
base dc=zell-aufmass,dc=de
# The DN to bind with for normal lookups.
binddn uid=Administrator,cn=users,dc=zell-aufmass,dc=de
bindpw 6%&6DdWMLzjS^i
scope sub
# SSL options
tls_cacertfile /etc/ssl/certs/ca-certificates.crt
EOF
# Schritt 2: System aktualisieren und grundlegende Pakete installieren
echo "Aktualisiere die Paketlisten und installiere grundlegende LDAP-Pakete..."
apt-get update && apt-get upgrade -y
apt-get install -y webmin-ldap-useradmin webmin-ldap-client ldap-utils libnss-ldap libpam-ldap
# Schritt 3: Hinweis zur Webmin-Konfiguration
echo -e "\n========================"
echo "Webmin-Setup benötigt:"
echo "Bitte initialisiere LDAP in Webmin manuell. Danach kann das Skript fortgesetzt werden."
echo "Drücke ENTER, wenn der LDAP-Setup abgeschlossen ist."
echo "========================"
read -p ""
# Schritt 4: /etc/nsswitch.conf anpassen
echo "Passe /etc/nsswitch.conf an..."
NSS_CONF="/etc/nsswitch.conf"
if [[ -f "$NSS_CONF" ]]; then
sed -i '/^passwd:/!b;/ ldap/! s/$/ ldap/' "$NSS_CONF"
sed -i '/^group:/!b;/ ldap/! s/$/ ldap/' "$NSS_CONF"
sed -i '/^shadow:/!b;/ ldap/! s/$/ ldap/' "$NSS_CONF"
else
echo "WARNUNG: Datei $NSS_CONF nicht gefunden!"
fi
# Schritt 5: /etc/ldap/ldap.conf erstellen oder ersetzen
echo "Erstelle oder ersetze /etc/ldap.conf..."
cat <<EOF > /etc/ldap.conf
base dc=zell-aufmass,dc=de
uri ldap://192.168.174.101:7389/
TLS_CACERT /etc/ssl/certs/ca-certificates.crt
binddn uid=Administrator,cn=users,dc=zell-aufmass,dc=de
bindpw 6%&6DdWMLzjS^i
nss_base_passwd cn=users,dc=zell-aufmass,dc=de
nss_base_shadow cn=users,dc=zell-aufmass,dc=de
nss_base_group cn=groups,dc=zell-aufmass,dc=de
EOF
# Schritt 6: Installiere nslcd und nscd
echo "Installiere nslcd und nscd..."
apt-get install -y nslcd nscd
# Schritt 7: Berechtigungen für /etc/nslcd.conf setzen
echo "Setze Berechtigungen für /etc/nslcd.conf..."
chmod 600 /etc/nslcd.conf
chown root:root /etc/nslcd.conf
# Schritt 8: nslcd-Dienst neu starten
echo "Starte den nslcd-Dienst neu..."
systemctl restart nslcd
# Schritt 9: libpam-mkhomedir installieren
echo "Installiere libpam-mkhomedir..."
apt-get install -y libpam-mkhomedir
# Schritt 10: /etc/pam.d/common-session und /etc/pam.d/common-session-noninteractive anpassen
echo "Passe PAM-Konfigurationen an..."
for FILE in /etc/pam.d/common-session /etc/pam.d/common-session-noninteractive; do
if [[ -f "$FILE" ]]; then
if ! grep -q "pam_mkhomedir.so" "$FILE"; then
echo "session required pam_mkhomedir.so skel=/etc/skel umask=0022" >> "$FILE"
fi
else
echo "WARNUNG: Datei $FILE nicht gefunden!"
fi
done
# Schritt 11: Erstelle und konfiguriere /srv/shared
echo "Erstelle und konfiguriere /srv/shared..."
mkdir -p /srv/shared
chown :ldapgroup /srv/shared
chmod 775 /srv/shared
# Schritt 12: Konfiguration testen
echo "Teste die Konfiguration mit 'getent passwd'..."
getent passwd
echo -e "\n========================"
echo "Skript abgeschlossen. Bitte überprüfe die Konfiguration manuell und melde Fehler."
echo "========================"