Skip to content

Instantly share code, notes, and snippets.

@dotsh
Last active October 3, 2018 15:37
Show Gist options
  • Save dotsh/3ad9b54e7948e681ed1dc5a5da1c694a to your computer and use it in GitHub Desktop.
Save dotsh/3ad9b54e7948e681ed1dc5a5da1c694a to your computer and use it in GitHub Desktop.
openldap simple install on CentOS
exit
## !!! ne pas executer comme un script !!! ##
### j'ai mis "exit" en haut pour eviter ça.
# il faut copier /coller chaque bloc de texte ci dessous dans un shell après avoir bien lu et compris
# il est préférable d'afficher ce document en RAW ( cf bouton sur la droite ) et de copier coller les here-documents en un bloc.
# un here-document c'est ce genre de chose :
#cat > truc << EOF
#blabla
#EOF
#
# - Mathieu VITRY, 2018 -
yum -y install compat-openldap openldap-clients openldap-devel openldap-servers
systemctl start slapd.service
systemctl enable slapd.service
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/*
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
export hashpw=$(/usr/sbin/slappasswd)
# attention là il faut donner un nouveau mot de passe admin
ldapmodify -Y EXTERNAL -H ldapi:/// << EOF
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=rennes,dc=lab
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=ldapadm,dc=rennes,dc=lab
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: ${hashpw}
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external, cn=auth" read by dn.base="cn=ldapadm,dc=rennes,dc=lab" read by * none
EOF
ldapadd -x -W -D "cn=ldapadm,dc=rennes,dc=lab" << EOF
dn: dc=rennes,dc=lab
dc: rennes
objectClass: top
objectClass: domain
dn: cn=ldapadm ,dc=rennes,dc=lab
objectClass: organizationalRole
cn: ldapadm
description: LDAP Manager
dn: ou=People,dc=rennes,dc=lab
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=rennes,dc=lab
objectClass: organizationalUnit
ou: Group
EOF
# attention là ça demande le mot de passe admin
# c'est bon, LDAP est configuré. ( en seulements 11 commandes )
### ajout d'un user ###
export newuser=bob
export newuseruid=9998
export newusergid=100
export newuserpassword=password123
export hashpass=$(/usr/sbin/slappasswd -s ${newuserpassword} | base64)
ldapadd -x -W -D "cn=ldapadm,dc=rennes,dc=lab" << EOF
dn: uid=${newuser},ou=People,dc=rennes,dc=lab
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: ${newuser}
uid: ${newuser}
uidNumber: ${newuseruid}
gidNumber: ${newusergid}
homeDirectory: /home/${newuser}
loginShell: /bin/bash
gecos: ${newuser}
userPassword: ${hashpass}
shadowLastChange: 17058
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
EOF
# attention là ça demande le mot de passe admin
# verification :
ldapsearch -x cn=bob -b dc=rennes,dc=lab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment