LDAP Server: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(20 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 2: Zeile 2:
  
 
* '''apt install slapd ldap-utils ldapscripts nslcd'''
 
* '''apt install slapd ldap-utils ldapscripts nslcd'''
 +
* '''dpkg-reconfigure -p low slapd'''
  
 
= Grundstruktur der Datenbank =
 
= Grundstruktur der Datenbank =
Zeile 9: Zeile 10:
 
* '''vim struktur.ldif'''
 
* '''vim struktur.ldif'''
  
  dn: ou=users,dc=lab100,dc=it
+
  dn: ou=users,dc=lab1''xx'',dc=it
 
  objectClass: organizationalUnit
 
  objectClass: organizationalUnit
 
  ou: users
 
  ou: users
 
   
 
   
  dn: ou=groups,dc=lab100,dc=it
+
  dn: ou=groups,dc=lab1''xx'',dc=it
 
  objectClass: organizationalUnit
 
  objectClass: organizationalUnit
 
  ou: groups
 
  ou: groups
 
   
 
   
  dn: ou=hosts,dc=lab100,dc=it
+
  dn: ou=hosts,dc=lab1''xx'',dc=it
 
  objectClass: organizationalUnit
 
  objectClass: organizationalUnit
 
  ou: hosts
 
  ou: hosts
* '''ldapadd -x -D cn=admin,dc=lab100,dc=it -w 123Start$ -f struktur.ldif'''
+
* '''ldapadd -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ -f struktur.ldif'''
  
  adding new entry "ou=users,dc=lab100,dc=it"
+
  adding new entry "ou=users,dc=lab1''xx'',dc=it"
 
   
 
   
  adding new entry "ou=groups,dc=lab100,dc=it"
+
  adding new entry "ou=groups,dc=lab1''xx'',dc=it"
 
   
 
   
  adding new entry "ou=hosts,dc=lab100,dc=it"
+
  adding new entry "ou=hosts,dc=lab1''xx'',dc=it"
  
 
= Einträge einfügen/löschen =
 
= Einträge einfügen/löschen =
Zeile 34: Zeile 35:
 
* '''vim group.ldif'''
 
* '''vim group.ldif'''
  
  dn: cn=it,ou=groups,dc=lab100,dc=it
+
  dn: cn=it,ou=groups,dc=lab1''xx'',dc=it
 
  objectClass: posixGroup
 
  objectClass: posixGroup
 
  cn: it
 
  cn: it
 
  gidNumber: 3001
 
  gidNumber: 3001
* '''ldapadd -x -D cn=admin,dc=lab -w 123Start$ -f group.ldif'''
 
  
  adding new entry "cn=it,ou=groups,dc=lab100,dc=it"
+
* '''ldapadd -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ -f group.ldif'''
 +
 
 +
  adding new entry "cn=it,ou=groups,dc=lab1''xx'',dc=it"
 +
* ''' ldapsearch -x -LLL -H  ldap://127.0.0.1 -b  dc=lab''xx'',dc=it'''
 
* '''vim user.ldif'''
 
* '''vim user.ldif'''
  
  dn: uid=leroy,ou=users,dc=lab100,dc=it
+
  dn: uid=leroy,ou=users,dc=lab1''xx'',dc=it
 
  cn: leroy
 
  cn: leroy
 
  objectClass: account
 
  objectClass: account
Zeile 53: Zeile 56:
 
  homeDirectory: /home/leroy
 
  homeDirectory: /home/leroy
 
  loginShell: /bin/bash
 
  loginShell: /bin/bash
* '''ldapadd -x -D cn=admin,dc=lab -w 123Start$ -f user.ldif'''
 
  
  adding new entry "uid=leroy,ou=users,dc=lab100,dc=it"
+
* '''ldapadd -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ -f user.ldif'''
 +
 
 +
  adding new entry "uid=leroy,ou=users,dc=lab1''xx'',dc=it"
 +
 
 +
* Einen Benutzer zu einer LDAP-Gruppe hinzufügen
 +
* '''vim ''add.ldif'' '''
 +
 
 +
dn: cn=it,ou=groups,dc=lab''xx'',dc=''it''
 +
changetype: modify
 +
add: memberUid
 +
memberUid: neuer.benutzer
 +
 
 +
* '''ldapmodify -x -D "cn=admin,dc=lab1''x'',dc=it" -W -f add.ldif'''
 +
 
 
* Alle Blätter eines Zweiges müssen zuerst gelöscht werden, bevor die darüberliegende Struktur gelöscht werden kann
 
* Alle Blätter eines Zweiges müssen zuerst gelöscht werden, bevor die darüberliegende Struktur gelöscht werden kann
* '''ldapdelete -x -D cn=admin,dc=lab -w 123Start$ “ou=hosts,dc=lab”'''
+
* '''ldapdelete -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ "ou=hosts,dc=lab1''xx'',dc=it"'''
* '''ldapdelete -x -D cn=admin,dc=lab -w 123Start$ “cn=it,ou=groups,dc=lab”'''
+
* '''ldapdelete -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ "cn=it,ou=groups,dc=lab1''xx'',dc=it"'''
* '''ldapdelete -x -D cn=admin,dc=lab -w 123Start$ “uid=leroy,ou=users,dc=lab”'''
+
* '''ldapdelete -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ "uid=leroy,ou=users,dc=lab1''xx'',dc=it"'''
* '''ldapdelete -x -D cn=admin,dc=lab -w 123Start$ “ou=groups,dc=lab”'''
+
* '''ldapdelete -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ "ou=groups,dc=lab1''xx'',dc=it"'''
* '''ldapdelete -x -D cn=admin,dc=lab -w 123Start$ “ou=users,dc=lab”'''
+
* '''ldapdelete -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ "ou=users,dc=lab1''xx'',dc=it"'''
  
 
= ldapscripts =
 
= ldapscripts =
Zeile 67: Zeile 82:
 
* Da das Füllen einer solchen Datenbank leicht automatisierbar ist, gibt es schon Skripte, die genau diese Aufgabe erfüllen
 
* Da das Füllen einer solchen Datenbank leicht automatisierbar ist, gibt es schon Skripte, die genau diese Aufgabe erfüllen
 
* Damit die Skripte funktionieren müssen aber die Grundstruktur da sein
 
* Damit die Skripte funktionieren müssen aber die Grundstruktur da sein
* '''ldapadd -x -D cn=admin,dc=lab100,dc=it -w 123Start$ -f struktur.ldif'''
+
* '''ldapadd -x -D cn=admin,dc=lab1''xx'',dc=it -w 123Start$ -f struktur.ldif'''
 
* '''vim /etc/ldapscripts/ldapscripts.conf'''
 
* '''vim /etc/ldapscripts/ldapscripts.conf'''
  
  SUFFIX="dc=lab100,dc=it"
+
SERVER="ldap://localhost"
 +
  SUFFIX="dc=lab1''xx'',dc=it"
 
  GSUFFIX="ou=groups"
 
  GSUFFIX="ou=groups"
 
  USUFFIX="ou=users"
 
  USUFFIX="ou=users"
 
  MSUFFIX="ou=hosts"
 
  MSUFFIX="ou=hosts"
  BINDDN="cn=admin,dc=lab100,dc=it"
+
  BINDDN="cn=admin,dc=lab1''xx'',dc=it"
 +
BINDPWDFILE="/etc/ldapscripts/ldapscripts.passwd"
 
  USHELL="/bin/bash"
 
  USHELL="/bin/bash"
 
  UHOMES="/home/%u"
 
  UHOMES="/home/%u"
 
  CREATEHOMES="yes"
 
  CREATEHOMES="yes"
 
  HOMESKEL="/etc/skel"
 
  HOMESKEL="/etc/skel"
  BINDPWDFILE="/etc/ldapscripts/ldapscripts.passwd"
+
  UIDSTART="10000" # User ID
 
  GIDSTART="10000" # Group ID
 
  GIDSTART="10000" # Group ID
UIDSTART="10000" # User ID
 
 
  MIDSTART="20000" # Machine ID
 
  MIDSTART="20000" # Machine ID
 
  GCLASS="posixGroup"  # Leave "posixGroup" here if not sure !
 
  GCLASS="posixGroup"  # Leave "posixGroup" here if not sure !
 
  PASSWORDGEN="pwgen"
 
  PASSWORDGEN="pwgen"
  RECORDPASSWORDS="no"
+
  RECORDPASSWORDS="yes"
 
  PASSWORDFILE="/var/log/ldapscripts_passwd.log"
 
  PASSWORDFILE="/var/log/ldapscripts_passwd.log"
 
  LOGTOFILE="yes"
 
  LOGTOFILE="yes"
Zeile 104: Zeile 120:
 
  UTEMPLATE=""
 
  UTEMPLATE=""
 
  MTEMPLATE=""
 
  MTEMPLATE=""
 +
* Zusätzlich muss das LDAP Admin-Passwort hinterlegt sein
 +
* '''echo -n "123Start$" > /etc/ldapscripts/ldapscripts.passwd'''
 +
 
* '''ldapaddgroup it'''
 
* '''ldapaddgroup it'''
  
 
  Successfully added group it to LDAP
 
  Successfully added group it to LDAP
 +
 
* '''ldapadduser leroy it'''
 
* '''ldapadduser leroy it'''
  
 
  Successfully added user leroy to LDAP
 
  Successfully added user leroy to LDAP
 
  Successfully set password for user leroy
 
  Successfully set password for user leroy
 +
 
* '''ldapsetpasswd leroy'''
 
* '''ldapsetpasswd leroy'''
  
 
  New Password:  
 
  New Password:  
 
  Retype New Password:  
 
  Retype New Password:  
  Successfully set password for user uid=leroy,ou=users,dc=lab100,dc=it
+
  Successfully set password for user uid=leroy,ou=users,dc=lab1''xx'',dc=it
  
 
= Testen =
 
= Testen =
  
* '''getent passwd | tail'''
+
* '''reboot'''
 +
* '''getent passwd'''
  
  systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
+
  ...
systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
 
messagebus:x:103:109::/nonexistent:/usr/sbin/nologin
 
systemd-timesync:x:104:110:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
 
sshd:x:105:65534::/run/sshd:/usr/sbin/nologin
 
 
  xinux:x:1000:1000:xinux,,,:/home/xinux:/bin/bash
 
  xinux:x:1000:1000:xinux,,,:/home/xinux:/bin/bash
 
  systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
 
  systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
 
  tcpdump:x:106:113::/nonexistent:/usr/sbin/nologin
 
  tcpdump:x:106:113::/nonexistent:/usr/sbin/nologin
 
  openldap:x:107:114:OpenLDAP Server Account,,,:/var/lib/ldap:/bin/false
 
  openldap:x:107:114:OpenLDAP Server Account,,,:/var/lib/ldap:/bin/false
  leroy:*:10000:10000:leroy:/home/leroy:/bin/bash
+
  '''leroy:*:10000:10000:leroy:/home/leroy:/bin/bash'''
* '''getent groups | tail'''
+
* '''getent group'''
  
  messagebus:x:109:
+
  ...
systemd-timesync:x:110:
 
ssh:x:111:
 
ssl-cert:x:112:
 
 
  xinux:x:1000:
 
  xinux:x:1000:
 
  systemd-coredump:x:999:
 
  systemd-coredump:x:999:
Zeile 142: Zeile 157:
 
  openldap:x:114:
 
  openldap:x:114:
 
  wireshark:x:115:xinux
 
  wireshark:x:115:xinux
  it:*:10001:
+
  '''it:*:10001:'''
 +
 
 +
[[Kategorie:LDAP]]

Aktuelle Version vom 10. September 2024, 06:43 Uhr

Benötigte Pakete

  • apt install slapd ldap-utils ldapscripts nslcd
  • dpkg-reconfigure -p low slapd

Grundstruktur der Datenbank

  • Einträge können mit ldapadd hinzugefügt werden
  • Damit der Befehl nicht zu unübersichtlich wird kann man den Eintrag auch in einer Datei definieren
  • vim struktur.ldif
dn: ou=users,dc=lab1xx,dc=it
objectClass: organizationalUnit
ou: users

dn: ou=groups,dc=lab1xx,dc=it
objectClass: organizationalUnit
ou: groups

dn: ou=hosts,dc=lab1xx,dc=it
objectClass: organizationalUnit
ou: hosts
  • ldapadd -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ -f struktur.ldif
adding new entry "ou=users,dc=lab1xx,dc=it"

adding new entry "ou=groups,dc=lab1xx,dc=it"

adding new entry "ou=hosts,dc=lab1xx,dc=it"

Einträge einfügen/löschen

Manuell

  • vim group.ldif
dn: cn=it,ou=groups,dc=lab1xx,dc=it
objectClass: posixGroup
cn: it
gidNumber: 3001
  • ldapadd -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ -f group.ldif
adding new entry "cn=it,ou=groups,dc=lab1xx,dc=it"
  • ldapsearch -x -LLL -H ldap://127.0.0.1 -b dc=labxx,dc=it
  • vim user.ldif
dn: uid=leroy,ou=users,dc=lab1xx,dc=it
cn: leroy
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
uid: leroy
uidNumber: 2001
gidNumber: 3001
homeDirectory: /home/leroy
loginShell: /bin/bash
  • ldapadd -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ -f user.ldif
adding new entry "uid=leroy,ou=users,dc=lab1xx,dc=it"
  • Einen Benutzer zu einer LDAP-Gruppe hinzufügen
  • vim add.ldif
dn: cn=it,ou=groups,dc=labxx,dc=it
changetype: modify
add: memberUid
memberUid: neuer.benutzer
  • ldapmodify -x -D "cn=admin,dc=lab1x,dc=it" -W -f add.ldif
  • Alle Blätter eines Zweiges müssen zuerst gelöscht werden, bevor die darüberliegende Struktur gelöscht werden kann
  • ldapdelete -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ "ou=hosts,dc=lab1xx,dc=it"
  • ldapdelete -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ "cn=it,ou=groups,dc=lab1xx,dc=it"
  • ldapdelete -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ "uid=leroy,ou=users,dc=lab1xx,dc=it"
  • ldapdelete -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ "ou=groups,dc=lab1xx,dc=it"
  • ldapdelete -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ "ou=users,dc=lab1xx,dc=it"

ldapscripts

  • Da das Füllen einer solchen Datenbank leicht automatisierbar ist, gibt es schon Skripte, die genau diese Aufgabe erfüllen
  • Damit die Skripte funktionieren müssen aber die Grundstruktur da sein
  • ldapadd -x -D cn=admin,dc=lab1xx,dc=it -w 123Start$ -f struktur.ldif
  • vim /etc/ldapscripts/ldapscripts.conf
SERVER="ldap://localhost"
SUFFIX="dc=lab1xx,dc=it"
GSUFFIX="ou=groups"
USUFFIX="ou=users"
MSUFFIX="ou=hosts"
BINDDN="cn=admin,dc=lab1xx,dc=it"
BINDPWDFILE="/etc/ldapscripts/ldapscripts.passwd"
USHELL="/bin/bash"
UHOMES="/home/%u"
CREATEHOMES="yes"
HOMESKEL="/etc/skel"
UIDSTART="10000" # User ID
GIDSTART="10000" # Group ID
MIDSTART="20000" # Machine ID
GCLASS="posixGroup"   # Leave "posixGroup" here if not sure !
PASSWORDGEN="pwgen"
RECORDPASSWORDS="yes"
PASSWORDFILE="/var/log/ldapscripts_passwd.log"
LOGTOFILE="yes"
LOGFILE="/var/log/ldapscripts.log"
LOGTOSYSLOG="no"
SYSLOGFACILITY="local4"
SYSLOGLEVEL="info"
LDAPSEARCHBIN="/usr/bin/ldapsearch"
LDAPADDBIN="/usr/bin/ldapadd"
LDAPDELETEBIN="/usr/bin/ldapdelete"
LDAPMODIFYBIN="/usr/bin/ldapmodify"
LDAPMODRDNBIN="/usr/bin/ldapmodrdn"
LDAPPASSWDBIN="/usr/bin/ldappasswd"
LDAPSEARCHOPTS="-o ldif-wrap=no"
GETENTPWCMD=""
GETENTGRCMD=""
GTEMPLATE=""
UTEMPLATE=""
MTEMPLATE=""
  • Zusätzlich muss das LDAP Admin-Passwort hinterlegt sein
  • echo -n "123Start$" > /etc/ldapscripts/ldapscripts.passwd
  • ldapaddgroup it
Successfully added group it to LDAP
  • ldapadduser leroy it
Successfully added user leroy to LDAP
Successfully set password for user leroy
  • ldapsetpasswd leroy
New Password: 
Retype New Password: 
Successfully set password for user uid=leroy,ou=users,dc=lab1xx,dc=it

Testen

  • reboot
  • getent passwd
...
xinux:x:1000:1000:xinux,,,:/home/xinux:/bin/bash
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
tcpdump:x:106:113::/nonexistent:/usr/sbin/nologin
openldap:x:107:114:OpenLDAP Server Account,,,:/var/lib/ldap:/bin/false
leroy:*:10000:10000:leroy:/home/leroy:/bin/bash
  • getent group
...
xinux:x:1000:
systemd-coredump:x:999:
tcpdump:x:113:
openldap:x:114:
wireshark:x:115:xinux
it:*:10001: