LDAP ( Lightweight Directory Access Protocol ) est un protocole qui permet d’accéder à des bases d’informations sur les utilisateurs d’un réseau par l’intermédiaire de protocoles TCP/IP.
Dans ce guide nous allons voir comment installer OpenLDAP sur CentOS 8 depuis la source, vous n’avez qu’à suivre les étapes ci-dessous.
Mettre à jour le système :
Taper la commande suivante pour mettre à jour CentOS 8 :
[root@server ~]# dnf upgrade -y
Une fois terminé, redémarrez le système :
[root@server ~]# reboot
Installation des Packages nécessaires :
Installer les packages ci-dessous requises pour installer OpenLDAP :
[root@server ~]# dnf install -y wget vim cyrus-sasl-devel libtool-ltdl-devel openssl-devel libdb-devel make libtool autoconf tar gcc perl perl-devel -y
Ajoutez le dépôt EPEL 7 qui contient les packages wiredtiger , pour cela créz un fichier sur /etc/yum.repos.d et y mettre les infos du dépos ci-dessous :
[root@server ~]# cat /etc/yum.repos.d/epel-el7.repo [epel-el7] name=Extra Packages for Enterprise Linux 7 - x86_64 baseurl=https://dl.fedoraproject.org/pub/epel/7/x86_64/ enabled=0 gpgcheck=0
Installer le package wiredtiger :
[root@server ~]# dnf --enablerepo=epel-el7 install wiredtiger wiredtiger-devel
Création du compte système LDAP :
[root@server ~]# useradd -r -M -d /var/lib/openldap -u 55 -s /usr/sbin/nologin ldap
Installer OpenLDAP depuis la source :
Au moment de ce tutoriel, la dernière version d’OpenLDAP était 2.5.7
Vous pouvez vérifier la dérnière version via ce lien.
Télecharger le package via la commande wget :
[root@server ~]# wget https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.5.7.tgz --2021-08-21 09:09:53-- https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.5.7.tgz Resolving www.openldap.org (www.openldap.org)… 45.79.47.170, 2600:3c00:e000:2d3::1 Connecting to www.openldap.org (www.openldap.org)|45.79.47.170|:443… connected HTTP request sent, awaiting response… 200 OK Length: 6426051 (6.1M) [application/octet-stream] Saving to: ‘openldap-2.5.7.tgz’ openldap-2.5.7.tgz 100%[=============================================================================>] 6.13M 1.58MB/s in 3.9s 2021-08-21 09:09:58 (1.58 MB/s) - ‘openldap-2.5.7.tgz’ saved [6426051/6426051]
[root@server ~]# ll
total 6280
-rw-------. 1 root root 1025 Jul 24 08:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 6426051 Aug 18 13:52 openldap-2.5.7.tgz
Extrayez le fichier avec la commande tar :
[root@server ~]# tar xzf openldap-2.5.7.tgz [root@server ~]# ll total 6284 -rw-------. 1 root root 1025 Jul 24 08:31 anaconda-ks.cfg drwxr-xr-x. 10 1001 1001 4096 Aug 18 13:11 openldap-2.5.7 -rw-r--r--. 1 root root 6426051 Aug 18 13:52 openldap-2.5.7.tgz
Installation OpenLDAP :
Allez au répertoire openldap-2.5.7/ et compilez les fichiers source avec la commande ci-dessous :
[root@server openldap-2.5.7]# ./configure --prefix=/usr --sysconfdir=/etc --disable-static \ --enable-debug --with-tls=openssl --with-cyrus-sasl --enable-dynamic \ --enable-crypt --enable-spasswd --enable-slapd --enable-modules \ --enable-rlookups --enable-backends=mod --disable-ndb --disable-sql \ --disable-shell --disable-bdb --disable-hdb --enable-overlays=mod configure: WARNING: unrecognized options: --disable-shell, --disable-bdb, --disable-hdb configure: loading site script /usr/share/config.site Configuring OpenLDAP 2.5.7-Release … checking build system type… x86_64-pc-linux-gnu checking host system type… x86_64-pc-linux-gnu checking target system type… x86_64-pc-linux-gnu checking configure arguments… done checking for cc… cc
Après une compilation réussie, vous devriez voir un message disant que vous devez exécuter la commande « make depend » :
Making servers/slapd/overlays/statover.c Please run "make depend" to build dependencies
Exécutez donc la commande « make depend » :
[root@server openldap-2.5.7]# make depend Making depend in /root/openldap-2.5.7 Entering subdirectory include make[1]: Entering directory '/root/openldap-2.5.7/include' Making ldap_config.h make[1]: Leaving directory '/root/openldap-2.5.7/include' Entering subdirectory libraries make[1]: Entering directory '/root/openldap-2.5.7/libraries' Making depend in /root/openldap-2.5.7/libraries Entering subdirectory liblutil make[2]: Entering directory '/root/openldap-2.5.7/libraries/liblutil' ../../build/mkdep -d "." -c "cc" -m "-M" -I../../include -I../../include base64.c entropy.c sasl.c signal.c hash.c passfile.c md5.c passwd.c sha1.c getpass.c lockf.c utils.c uuid.c sockpair.c meter.c getpeereid.c detach.c make[2]: Leaving directory '/root/openldap-2.5.7/libraries/liblutil'
Compilez ensuite avec « make » :
[root@server openldap-2.5.7]# make
Enfin installer OpenLDAP avec la commande ci-dessous :
[root@server openldap-2.5.7]# make install
Après une installation résussite, les fichiers et répertoires suivant sont créés au niveau du répertoire /etc/openldap :
[root@server openldap-2.5.7]# ll /etc/openldap total 28 drwxr-xr-x. 2 root root 6 Jun 29 13:25 certs -rw-r--r--. 1 root root 900 Jun 29 13:25 ldap.conf -rw-r--r--. 1 root root 247 Aug 21 12:07 ldap.conf.default drwxr-xr-x. 2 root root 4096 Aug 21 12:08 schema -rw-------. 1 root root 2680 Aug 21 12:08 slapd.conf -rw-------. 1 root root 2680 Aug 21 12:08 slapd.conf.default -rw-------. 1 root root 2731 Aug 21 12:08 slapd.ldif -rw-------. 1 root root 2731 Aug 21 12:08 slapd.ldif.default
Configuration du openLDAP :
Il faut d’abord créer les répertoires de base de donées suivantes :
[root@server openldap-2.5.7]# mkdir /var/lib/openldap /etc/openldap/slapd.d
Mettez le proprietaries et les permissions pour le repertoire et fichier ci-dessous :
Création du shéma de openldap sudo :
Vérifier si la version de « sudo » support ldap :
[root@server openldap-2.5.7]# sudo -V | grep -i "ldap" Configure options: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --prefix=/usr --sbindir=/usr/sbin --libdir=/usr/lib64 --docdir=/usr/share/doc/sudo --disable-root-mailer --with-logging=syslog --with-logfac=authpriv --with-pam --with-pam-login --with-editor=/bin/vi --with-env-editor --with-ignore-dot --with-tty-tickets --with-ldap --with-ldap-conf-file=/etc/sudo-ldap.conf --with-selinux --with-passprompt=[sudo] password for %p: --with-linux-audit --with-sssd ldap.conf path: /etc/sudo-ldap.conf ldap.secret path: /etc/ldap.secret
[root@server openldap-2.5.7]# cp /usr/share/doc/sudo/schema.OpenLDAP /etc/openldap/schema/sudo.schema
Créez lr fichier ci-dessous et y mettre le contenu suivante :
[root@server openldap-2.5.7]# cat /etc/openldap/schema/sudo.ldif dn: cn=sudo,cn=schema,cn=config objectClass: olcSchemaConfig cn: sudo olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.1 NAME 'sudoUser' DESC 'User(s) who may run sudo' EQUALITY caseExactIA5Match SUBSTR caseExactIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.2 NAME 'sudoHost' DESC 'Host(s) who may run sudo' EQUALITY caseExactIA5Match SUBSTR caseExactIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.3 NAME 'sudoCommand' DESC 'Command(s) to be executed by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.4 NAME 'sudoRunAs' DESC 'User(s) impersonated by sudo (deprecated)' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.5 NAME 'sudoOption' DESC 'Options(s) followed by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.6 NAME 'sudoRunAsUser' DESC 'User(s) impersonated by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcAttributeTypes: ( 1.3.6.1.4.1.15953.9.1.7 NAME 'sudoRunAsGroup' DESC 'Group(s) impersonated by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) olcObjectClasses: ( 1.3.6.1.4.1.15953.9.2.1 NAME 'sudoRole' SUP top STRUCTURAL DESC 'Sudoer Entries' MUST ( cn ) MAY ( sudoUser $ sudoHost $ sudoCommand $ sudoRunAs $ sudoRunAsUser $ sudoRunAsGroup $ sudoOption $ description ) )
Configurer la base de données de slapd :
Renommer le fichier slapd.ldif en slapd.ldif.bak pour un garder backup :
[root@server openldap-2.5.7]# mv /etc/openldap/slapd.ldif /etc/openldap/slapd.ldif.bak
Créer un nouveau fichier slapd.ldif et y mettre le contenu ci-dessous :
[root@server openldap-2.5.7]# slapadd -n 0 -F /etc/openldap/slapd.d -l /etc/openldap/slapd.ldif -u [root@server openldap-2.5.7]# slapadd -n 0 -F /etc/openldap/slapd.d -l /etc/openldap/slapd.ldif Closing DB…
Ces commande permettent de créer le répertoire et fichier ci-dessous :
[root@server openldap-2.5.7]# ls /etc/openldap/slapd.d 'cn=config' 'cn=config.ldif'
Changer le propriétaire du répéertoire ci-dessous :
[root@server openldap-2.5.7]# chown -R ldap:ldap /etc/openldap/slapd.d
Création du OpenLDAP service :
Créer le fichier « slapd.service » et y mettre le contenu ci-dessous :
# vim /etc/systemd/system/slapd.service
[Unit] Description=OpenLDAP Server Daemon After=syslog.target network-online.target Documentation=man:slapd Documentation=man:slapd-mdb [Service] Type=forking PIDFile=/var/lib/openldap/slapd.pid Environment="SLAPD_URLS=ldap:/// ldapi:/// ldaps:///" Environment="SLAPD_OPTIONS=-F /etc/openldap/slapd.d" ExecStart=/usr/libexec/slapd -u ldap -g ldap -h ${SLAPD_URLS} $SLAPD_OPTIONS [Install] WantedBy=multi-user.target
Redémarrer le daemon:
[root@server openldap-2.5.7]# systemctl daemon-reload
Ensuite démarrer le service slapd :
[root@server openldap-2.5.7]# systemctl enable --now slapd
Vérifiez le status du service :
[root@server openldap-2.5.7]# systemctl status slapd.service ● slapd.service - OpenLDAP Server Daemon Loaded: loaded (/etc/systemd/system/slapd.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2021-08-21 13:21:12 EDT; 52min ago Docs: man:slapd man:slapd-mdb Process: 79058 ExecStart=/usr/libexec/slapd -u ldap -g ldap -h ${SLAPD_URLS} $SLAPD_OPTIONS (code=exited, status=0/SUCCESS) Main PID: 79060 (slapd) Tasks: 2 (limit: 4190) Memory: 3.8M CGroup: /system.slice/slapd.service └─79060 /usr/libexec/slapd -u ldap -g ldap -h ldap:/// ldapi:/// ldaps:/// -F /etc/openldap/slapd.d Aug 21 13:20:32 server systemd[1]: Starting OpenLDAP Server Daemon… Aug 21 13:20:52 server slapd[79058]: @(#) $OpenLDAP: slapd 2.5.7 (Aug 21 2021 11:59:45) $ root@server:/root/openldap-2.5.7/servers/slapd Aug 21 13:21:12 server slapd[79060]: slapd starting Aug 21 13:21:12 server systemd[1]: Started OpenLDAP Server Daemon.
Maintenant que notre Openldap est bien installé nous allons voir comment le configurer.
Comment voir le contenu des fichiers compressés sous linux
Comment enregistrer et souscrire un système Red Hat
df/dh Taille des files system et répertoires
Migration de CentOS 7 vers CentOS Stream
Fail2Ban : How to protect Linux services