{"id":4731,"date":"2019-11-10T22:36:25","date_gmt":"2019-11-10T19:36:25","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4731"},"modified":"2024-03-12T23:20:23","modified_gmt":"2024-03-12T20:20:23","slug":"install-and-setup-openldap-on-centos-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-setup-openldap-on-centos-8\/","title":{"rendered":"Install and Setup OpenLDAP on CentOS 8"},"content":{"rendered":"\n<p>In this guide, we provide a step by step tutorial on how to install and setup OpenLDAP on CentOS 8. If you are here, then you already know what an OpenLDAP server is and thus the description of what it is is beyond the scope of this tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing OpenLDAP on CentOS 8<\/h2>\n\n\n\n<p>Well, CentOS 8 repositories do not have the latest release versions of OpenLDAP. The available version of OpenLDAP provided by CentOS 8 <a rel=\"noreferrer noopener\" aria-label=\"PowerTools, is OpenLDAP server v2.4.46 (opens in a new tab)\" href=\"https:\/\/centos.pkgs.org\/8\/centos-powertools-x86_64\/openldap-servers-2.4.46-9.el8.x86_64.rpm.html\" target=\"_blank\">PowerTools repos, is OpenLDAP server v2.4.46<\/a>. To get the latest version with bug fixes, you need to build it from the source as described in this guide.<\/p>\n\n\n\n<p>You may want to use other alternatives to OpenLDAP such as FreeIPA;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-setup-freeipa-server-on-centos-8\/\" target=\"_blank\">Install and Setup FreeIPA Server on CentOS 8<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Run System Update<\/h3>\n\n\n\n<p>To update your system packages, run the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install Required Dependencies and Build Tools<\/h3>\n\n\n\n<p>There are quite a number of dependencies and build tools required for a successful build and compilation OpenLDAP from the source. Run the command below to install them.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install cyrus-sasl-devel make libtool autoconf libtool-ltdl-devel openssl-devel libdb-devel tar gcc perl perl-devel wget vim<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP System Account<\/h3>\n\n\n\n<p>In this demo, OpenLDAP will run with a non-privileged system user. Hence, run the command below to create OpenLDAP system user with custom user and group id;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd -r -M -d \/var\/lib\/openldap -u 55 -s \/usr\/sbin\/nologin ldap<\/code><\/pre>\n\n\n\n<p>Consult <code>man useradd<\/code> for the description of the command line options used above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Download OpenLDAP Source Tarball<\/h3>\n\n\n\n<p>The latest stable release of OpenLDAP as of this writing is OpenLDAP 2.4.48. Navigate to the <a rel=\"noreferrer noopener\" aria-label=\"OpenLDAP download&#039;s page (opens in a new tab)\" href=\"http:\/\/www.openldap.org\/software\/download\/\" target=\"_blank\">OpenLDAP download&#8217;s page<\/a> and grab the tarball.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>VER=2.4.48<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget ftp:\/\/ftp.openldap.org\/pub\/OpenLDAP\/openldap-release\/openldap-$VER.tgz<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Extract the OpenLDAP Source Tarball<\/h3>\n\n\n\n<p>The tarball can be extracted by running the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tar xzf openldap-$VER.tgz<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Compiling OpenLDAP<\/h3>\n\n\n\n<p>To compile OpenLDAP on CentOS 8, you first need to run the configure script to adapt OpenLDAP to your system and check if any required dependency is missing before you can proceed with installation.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cd openldap-$VER<\/code><\/pre>\n\n\n\n<p>With configure script, you can enable or disable various options while building OpenLDAP.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.\/configure --prefix=\/usr --sysconfdir=\/etc --disable-static \\\n--enable-debug --with-tls=openssl --with-cyrus-sasl --enable-dynamic \\\n--enable-crypt --enable-spasswd --enable-slapd --enable-modules \\\n--enable-rlookups --enable-backends=mod --disable-ndb --disable-sql \\\n--disable-shell --disable-bdb --disable-hdb --enable-overlays=mod<\/code><\/pre>\n\n\n\n<p>To learn more about the configuration options, consult;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.\/configure --help<\/code><\/pre>\n\n\n\n<p>If the configure script completes with no issues, the last line you should see is;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>Please run \"make depend\" to build dependencies<\/strong><\/code><\/pre>\n\n\n\n<p>As the line states, you need to run the <code><strong>make depend<\/strong><\/code> command to build OpenLDAP dependencies.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make depend<\/code><\/pre>\n\n\n\n<p>Next, compile OpenLDAP on CentOS 8.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make<\/code><\/pre>\n\n\n\n<p>If you got time and patience, you can run the test suite to verify OpenLDAP build for any errors. You can however skip this step.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make test<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Installing OpenLDAP on CentOS 8<\/h3>\n\n\n\n<p>If the compilation of OpenLDAP completes successfully, proceed to install it by running the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install<\/code><\/pre>\n\n\n\n<p>OpenLDAP configuration files are now installed on <code>\/etc\/openldap<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls \/etc\/openldap\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>certs  ldap.conf  ldap.conf.default  schema  slapd.conf  slapd.conf.default  slapd.ldif  slapd.ldif.default<\/code><\/pre>\n\n\n\n<p>The libraries are installed under <code>\/usr\/libexec\/openldap<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring OpenLDAP on CentOS 8<\/h3>\n\n\n\n<p>Now that the installation of OpenLDAP is complete, proceed to configure it.<\/p>\n\n\n\n<p>Create OpenLDAP data and database directories<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/var\/lib\/openldap \/etc\/openldap\/slapd.d<\/code><\/pre>\n\n\n\n<p>Set the proper ownership and permissions on OpenLDAP directories and configuration files.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown -R ldap:ldap \/var\/lib\/openldap<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown root:ldap \/etc\/openldap\/slapd.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chmod 640 \/etc\/openldap\/slapd.conf<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP Systemd Service<\/h3>\n\n\n\n<p>In order to run OpenLDAP as a service, you need to create a systemd service file as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/systemd\/system\/slapd.service<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=OpenLDAP Server Daemon\nAfter=syslog.target network-online.target\nDocumentation=man:slapd\nDocumentation=man:slapd-mdb\n\n&#91;Service]\nType=forking\nPIDFile=\/var\/lib\/openldap\/slapd.pid\nEnvironment=\"SLAPD_URLS=ldap:\/\/\/ ldapi:\/\/\/ ldaps:\/\/\/\"\nEnvironment=\"SLAPD_OPTIONS=-F \/etc\/openldap\/slapd.d\"\nExecStart=\/usr\/libexec\/slapd -u ldap -g ldap -h ${SLAPD_URLS} $SLAPD_OPTIONS\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>Save and quit the service file. <strong>Do not run the service yet<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP SUDO Schema<\/h3>\n\n\n\n<p>To configure LDAP with support <code>sudo<\/code>, first, check if your version of installed sudo supports LDAP.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo -V |  grep -i \"ldap\"<\/code><\/pre>\n\n\n\n<p>If sudo supports LDAP, you should see the lines below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\nldap.conf path: \/etc\/sudo-ldap.conf\nldap.secret path: \/etc\/ldap.secret<\/code><\/pre>\n\n\n\n<p>Check if LDAP sudo schema is available.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>rpm -ql sudo |  grep -i schema.openldap<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/usr\/share\/doc\/sudo\/schema.OpenLDAP<\/code><\/pre>\n\n\n\n<p>Copy the <code>schema.OpenLDAP<\/code> to the schema directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp \/usr\/share\/doc\/sudo\/schema.OpenLDAP  \/etc\/openldap\/schema\/sudo.schema<\/code><\/pre>\n\n\n\n<p>Next, you need to create sudo schema ldif file. Run the command below to create the <code><strong>sudo.ldif<\/strong><\/code> file. This ldif file is obtained from <a href=\"https:\/\/github.com\/Lullabot\/openldap-schema\/blob\/master\/sudo.ldif\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Lullabot github repository (opens in a new tab)\">Lullabot github repository<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &lt;&lt; 'EOL' &gt; \/etc\/openldap\/schema\/sudo.ldif\ndn: cn=sudo,cn=schema,cn=config\nobjectClass: olcSchemaConfig\ncn: sudo\nolcAttributeTypes: ( 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 )\nolcAttributeTypes: ( 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 )\nolcAttributeTypes: ( 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 )\nolcAttributeTypes: ( 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 )\nolcAttributeTypes: ( 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 )\nolcAttributeTypes: ( 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 )\nolcAttributeTypes: ( 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 )\nolcObjectClasses: ( 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 ) )\nEOL<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Update SLAPD Database<\/h3>\n\n\n\n<p>Edit the SLAPD LDIF file, <code><strong>\/etc\/openldap\/slapd.ldif<\/strong><\/code>, and update it as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mv \/etc\/openldap\/slapd.ldif \/etc\/openldap\/slapd.ldif.bak<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vi \/etc\/openldap\/slapd.ldif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: cn=config\nobjectClass: olcGlobal\ncn: config\nolcArgsFile: \/var\/lib\/openldap\/slapd.args\nolcPidFile: \/var\/lib\/openldap\/slapd.pid\n\ndn: cn=schema,cn=config\nobjectClass: olcSchemaConfig\ncn: schema\n\ndn: cn=module,cn=config\nobjectClass: olcModuleList\ncn: module\nolcModulepath: \/usr\/libexec\/openldap\nolcModuleload: back_mdb.la\n\ninclude: file:\/\/\/etc\/openldap\/schema\/core.ldif\ninclude: file:\/\/\/etc\/openldap\/schema\/cosine.ldif\ninclude: file:\/\/\/etc\/openldap\/schema\/nis.ldif\ninclude: file:\/\/\/etc\/openldap\/schema\/inetorgperson.ldif\ninclude: file:\/\/\/etc\/openldap\/schema\/ppolicy.ldif\n<strong>include: file:\/\/\/etc\/openldap\/schema\/sudo.ldif<\/strong>\n\ndn: olcDatabase=frontend,cn=config\nobjectClass: olcDatabaseConfig\nobjectClass: olcFrontendConfig\nolcDatabase: frontend\nolcAccess: to dn.base=\"cn=Subschema\" by * read\nolcAccess: to * \n  by dn.base=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\" manage \n  by * none\n\ndn: olcDatabase=config,cn=config\nobjectClass: olcDatabaseConfig\nolcDatabase: config\nolcRootDN: cn=config\nolcAccess: to * \n  by dn.base=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\" manage \n  by * none<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To update the SLAPD database from the information provided on the SLAPD LDIF file above, use <code><strong>slapadd<\/strong><\/code> command with the option <code><strong>-n 0<\/strong><\/code> which creates the first database.<\/li>\n\n\n\n<li>To specify the configuration directory, <strong><code>\/etc\/openldap\/slapd.d<\/code><\/strong>, use option <strong><code>-F<\/code><\/strong> and option <strong><code>-l<\/code><\/strong> to specify location of the LDIF file above.<\/li>\n<\/ul>\n\n\n\n<p>Before you can write the changes to the database, perform a dry run to see what would happen. Pass <strong><code>-u<\/code><\/strong> option to slapadd command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>slapadd -n 0 -F \/etc\/openldap\/slapd.d -l \/etc\/openldap\/slapd.ldif -u<\/code><\/pre>\n\n\n\n<p>If the command above executes with no error, implement the changes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>slapadd -n 0 -F <code>\/etc\/openldap\/slapd.d<\/code> -l \/etc\/openldap\/slapd.ldif<\/code><\/pre>\n\n\n\n<p>This command creates slapd database configurations under <code>\/etc\/openldap\/slapd.d<\/code> directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls <code>\/etc\/openldap\/slapd.d<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>'cn=config'  'cn=config.ldif'<\/code><\/pre>\n\n\n\n<p>Set the user and group ownership of the <code>\/etc\/openldap\/slapd.d<\/code> directory and the files in it to ldap user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown -R ldap:ldap \/etc\/openldap\/slapd.d<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running SLAPD Service<\/h3>\n\n\n\n<p>Reload systemd configurations and start and enable OpenLDAP service to run on boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl daemon-reload<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now slapd<\/code><\/pre>\n\n\n\n<p>Check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status slapd<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\u25cf slapd.service - OpenLDAP Server Daemon\n   Loaded: loaded (\/etc\/systemd\/system\/slapd.service; enabled; vendor preset: disabled)\n   Active: active (running) since Sat 2019-12-07 12:10:52 EST; 6s ago\n     Docs: man:slapd\n           man:slapd-mdb\n  Process: 14975 ExecStart=\/usr\/libexec\/slapd -u ldap -g ldap -h ${SLAPD_URLS} $SLAPD_OPTIONS (code=exited, status=0\/SUCCESS)\n Main PID: 14976 (slapd)\n    Tasks: 2 (limit: 5061)\n   Memory: 3.0M\n   CGroup: \/system.slice\/slapd.service\n           \u2514\u250014976 \/usr\/libexec\/slapd -u ldap -g ldap -h ldap:\/\/\/ ldapi:\/\/\/ ldaps:\/\/\/ -F \/etc\/openldap\/slapd.d<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure OpenLDAP Logging on CentOS 8<\/h3>\n\n\n\n<p>To enable OpenLDAP to log connections, operations, results statistics, create and ldif file and update the database as follows. Such OpenLDAP logging is enabled on<a rel=\"noreferrer noopener\" href=\"https:\/\/www.openldap.org\/doc\/admin24\/slapdconfig.html\" target=\"_blank\">&nbsp;log level&nbsp;<\/a><code><a rel=\"noreferrer noopener\" href=\"https:\/\/www.openldap.org\/doc\/admin24\/slapdconfig.html\" target=\"_blank\">256<\/a><\/code><a rel=\"noreferrer noopener\" href=\"https:\/\/www.openldap.org\/doc\/admin24\/slapdconfig.html\" target=\"_blank\">&nbsp;with keyword&nbsp;<\/a><code><a rel=\"noreferrer noopener\" href=\"https:\/\/www.openldap.org\/doc\/admin24\/slapdconfig.html\" target=\"_blank\">stats<\/a><\/code> by modifying the&nbsp;<code>olcLogLevel<\/code>&nbsp;attribute as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim enable-ldap-log.ldif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: cn=config\nchangeType: modify\nreplace: olcLogLevel\nolcLogLevel: stats<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapmodify -Y external -H ldapi:\/\/\/ -f enable-ldap-log.ldif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapsearch -Y EXTERNAL -H ldapi:\/\/\/ -b cn=config \"(objectClass=olcGlobal)\" olcLogLevel -LLL -Q<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: cn=config\nolcLogLevel: stats<\/code><\/pre>\n\n\n\n<p>Configure Rsyslog to enable OpenLDAP to log to a specific file. By default, OpenLDAP logs to&nbsp;<code>local4<\/code>&nbsp;facility.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"local4.* \/var\/log\/slapd.log\" &gt;&gt; \/etc\/rsyslog.conf<\/code><\/pre>\n\n\n\n<p>Restart Rsyslog<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart rsyslog<\/code><\/pre>\n\n\n\n<p>You should now be able to read the LDAP logs on,&nbsp;<code>\/var\/log\/slapd.log<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP Default Root DN<\/h3>\n\n\n\n<p>Next, create MDB database defining the root DN as well as the access control lists.<\/p>\n\n\n\n<p>First, generate the root DN password.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>slappasswd<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>New password: <strong>ENTER PASSWORD<\/strong>\nRe-enter new password: <strong>RE-ENTER PASSWORD<\/strong>\n{SSHA}qAZah0xybYLcMfPUAN0SG4ki8JxC4bIF<\/code><\/pre>\n\n\n\n<p>Paste the password hash generated above as the value of <strong><code>olcRootPW<\/code><\/strong> in the Root DN ldif file below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim rootdn.ldif<\/code><\/pre>\n\n\n\n<p>Replace the domain components, <code><strong>dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong><\/code> with your appropriate names.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: olcDatabase=mdb,cn=config\nobjectClass: olcDatabaseConfig\nobjectClass: olcMdbConfig\nolcDatabase: mdb\nolcDbMaxSize: 42949672960\nolcDbDirectory: \/var\/lib\/openldap\nolcSuffix: dc=ldapmaster,dc=kifarunix-demo,dc=com\nolcRootDN: cn=admin,dc=ldapmaster,dc=kifarunix-demo,dc=com\n<strong>olcRootPW: {SSHA}5Hcgjj4gtcr\/exLcdSRuYgH6bFhIqkSe<\/strong>\nolcDbIndex: uid pres,eq\nolcDbIndex: cn,sn pres,eq,approx,sub\nolcDbIndex: mail pres,eq,sub\nolcDbIndex: objectClass pres,eq\nolcDbIndex: loginShell pres,eq\n<strong>olcDbIndex: sudoUser,sudoHost pres,eq<\/strong>\nolcAccess: to attrs=userPassword,shadowLastChange,shadowExpire\n  by self write\n  by anonymous auth\n  by dn.subtree=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\" manage \n  by dn.subtree=\"ou=system,dc=ldapmaster,dc=kifarunix-demo,dc=com\" read\n  by * none\nolcAccess: to dn.subtree=\"ou=system,dc=ldapmaster,dc=kifarunix-demo,dc=com\" by dn.subtree=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\" manage\n  by * none\nolcAccess: to dn.subtree=\"dc=ldapmaster,dc=kifarunix-demo,dc=com\" by dn.subtree=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\" manage\n  by users read \n  by * none<\/code><\/pre>\n\n\n\n<p>Read more about ACL on <a href=\"https:\/\/www.openldap.org\/doc\/admin24\/access-control.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"OpenLDAP Access Control (opens in a new tab)\">OpenLDAP Access Control<\/a>.<\/p>\n\n\n\n<p>Updated the slapd database with the content above;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f rootdn.ldif<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure OpenLDAP with SSL\/TLS<\/h3>\n\n\n\n<p>To secure OpenLDAP communication between the client and the server, configured it to use SSL\/TLS certificates.<\/p>\n\n\n\n<p>In this guide, we are self-signed certificates. You can choose to obtain the commercially signed and trusted certificates from your preferred CAs, for production environments.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \\\n\/etc\/pki\/tls\/ldapserver.key -out \/etc\/pki\/tls\/ldapserver.crt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown ldap:ldap \/etc\/pki\/tls\/{ldapserver.crt,ldapserver.key}<\/code><\/pre>\n\n\n\n<p>Update the OpenLDAP Server TLS certificates attributes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vi add-tls.ldif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>dn: cn=config\nchangetype: modify\nadd: olcTLSCACertificateFile\nolcTLSCACertificateFile: \/etc\/pki\/tls\/ldapserver.crt\n-\nadd: olcTLSCertificateKeyFile\nolcTLSCertificateKeyFile: \/etc\/pki\/tls\/ldapserver.key\n-\nadd: olcTLSCertificateFile\nolcTLSCertificateFile: \/etc\/pki\/tls\/ldapserver.crt<\/code><\/pre>\n\n\n\n<p>Note that we have used self-signed certificate as both the certificate and the CA certificate.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f add-tls.ldif<\/code><\/pre>\n\n\n\n<p>You can confirm this by running;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>slapcat -b \"cn=config\" | grep olcTLS<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>olcTLSCACertificateFile: \/etc\/pki\/tls\/ldapserver.crt\nolcTLSCertificateKeyFile: \/etc\/pki\/tls\/ldapserver.key\nolcTLSCertificateFile: \/etc\/pki\/tls\/ldapserver.crt<\/code><\/pre>\n\n\n\n<p>Change the location of the CA certificate on <code>\/etc\/openldap\/ldap.conf<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/openldap\/ldap.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\n#TLS_CACERT     \/etc\/pki\/tls\/cert.pem\n<strong>TLS_CACERT     \/etc\/pki\/tls\/ldapserver.crt<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP Base DN<\/h3>\n\n\n\n<p>Next, create your base DN or search base to define your organization structure and directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim basedn.ldif<\/code><\/pre>\n\n\n\n<p>Replace the domain components and organization units accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dn: dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: dcObject\nobjectClass: organization\nobjectClass: top\no: Kifarunix-demo\ndc: ldapmaster\n\ndn: ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: organizationalUnit\nobjectClass: top\nou: groups\n\ndn: ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: organizationalUnit\nobjectClass: top\nou: people<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f basedn.ldif<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP User Accounts<\/h3>\n\n\n\n<p>You can add users to your OpenLDAP server. Create an ldif file to define your users as follows.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim users.ldif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: uid=johndoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: inetOrgPerson\nobjectClass: posixAccount\nobjectClass: shadowAccount\nuid: johndoe\ncn: John\nsn: Doe\nloginShell: \/bin\/bash\nuidNumber: 10000\ngidNumber: 10000\nhomeDirectory: \/home\/johndoe\nshadowMax: 60\nshadowMin: 1\nshadowWarning: 7\nshadowInactive: 7\nshadowLastChange: 0\n\ndn: cn=johndoe,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: posixGroup\ncn: johndoe\ngidNumber: 10000\nmemberUid: johndoe<\/code><\/pre>\n\n\n\n<p>Add the user to the OpenLDAP database.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f users.ldif<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting password for LDAP User<\/h4>\n\n\n\n<p>To set the password for user above, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldappasswd -H ldapi:\/\/\/ -Y EXTERNAL -S \"uid=johndoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create OpenLDAP Bind DN and Bind DN User<\/h3>\n\n\n\n<p>Bind DN user is used for performing LDAP operations such as resolving User IDs and group IDs. In this guide, we create a bind DN ou called <code>system<\/code>. Note the access controls associated with this ou as defined on the root DN above.<\/p>\n\n\n\n<p>List the Access control lists on the database;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:\/\/\/ -b cn=config '(olcDatabase={1}mdb)' olcAccess<\/code><\/pre>\n\n\n\n<p>Create the BindDN user password.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>slappasswd<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>New password: Password\nRe-enter new password: Password\n<strong>{SSHA}Z7qPE2f8oRfHMo1DSbzdOqbr4jNgqBpC<\/strong><\/code><\/pre>\n\n\n\n<p>Paste the password hash value above as the value of <strong><code>userPassword<\/code><\/strong> attribute in the file below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim bindDNuser.ldif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dn: ou=system,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: organizationalUnit\nobjectClass: top\nou: system\n\ndn: cn=readonly,ou=system,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: organizationalRole\nobjectClass: simpleSecurityObject\ncn: readonly\nuserPassword: <strong>{SSHA}Z7qPE2f8oRfHMo1DSbzdOqbr4jNgqBpC<\/strong>\ndescription: Bind DN user for LDAP Operations<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f bindDNuser.ldif<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Allow OpenLDAP Service on Firewall<\/h3>\n\n\n\n<p>To allow remote clients to query OpenLDAP server, allow the <code>ldap<\/code> <strong>(389 UDP\/TCP)<\/strong> and <code>ldaps<\/code> (636 UDP\/TCP) service on firewall.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --add-service={ldap,ldaps} --permanent<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing OpenLDAP Authentication<\/h3>\n\n\n\n<p>Well, there you go. You have learnt how to install and setup OpenLDAP server on CentOS 8. To verify that users can actually connect to the systems via the OpenLDAP server, you need to configure OpenLDAP clients on the remote systems.<\/p>\n\n\n\n<p>Note that you can also use phpLDAPadmin to manage and administer your OpenLDAP. Learn how to install phpLDAPadmin on CentOS 8.<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-phpldapadmin-on-centos-8\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install phpLDAPadmin on CentOS 8<\/a><\/p>\n\n\n\n<p>In our next guide, we will learn how to install and setup OpenLDAP clients on CentOS 8.<\/p>\n\n\n\n<p>Want to configure OpenLDAP to provide SUDO rights to your clients? check the link below;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"How to Configure SUDO via OpenLDAP (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-configure-sudo-via-openldap-server\/\" target=\"_blank\">How to Configure SUDO via OpenLDAP Serve<\/a><a href=\"https:\/\/kifarunix.com\/how-to-configure-sudo-via-openldap-server\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"How to Configure SUDO via OpenLDAP (opens in a new tab)\">r<\/a><\/p>\n\n\n\n<p>Meanwhile, you can check out our other guides on OpenLDAP by following the links below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-create-openldap-member-groups\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Create OpenLDAP Member Groups<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/configure-sssd-for-openldap-client-authentication-on-debian-10-9\/\" target=\"_blank\">Configure SSSD for OpenLDAP Client Authentication on Debian 10\/9<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/setup-openldap-server-with-ssl-tls-on-debian-10\/\" target=\"_blank\">Setup OpenLDAP Server with SSL\/TLS on Debian 10<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-openldap-server-on-fedora-29\/\" target=\"_blank\">Install and Configure OpenLDAP server on Fedora 29<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/configure-openldap-client-on-debian-9-stretch\/\" target=\"_blank\">Configure OpenLDAP Client on Debian 9 Stretch<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-openldap-server-on-debian-9-stretch\/\" target=\"_blank\">Install and Configure OpenLDAP Server on Debian 9 Stretch<\/a><\/p>\n\n\n\n<p>Reference:<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"Compile OpenLDAP 2.4.48 (opens in a new tab)\" href=\"http:\/\/www.linuxfromscratch.org\/blfs\/view\/svn\/server\/openldap.html\" target=\"_blank\">Compile OpenLDAP 2.4.48<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.openldap.org\/doc\/admin24\/install.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Building and Installing OpenLDAP Software (opens in a new tab)\">Building and Installing OpenLDAP Software<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we provide a step by step tutorial on how to install and setup OpenLDAP on CentOS 8. If you are here, then<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,285,1099],"tags":[1142,1215,286,1214,1216],"class_list":["post-4731","post","type-post","status-publish","format-standard","hentry","category-howtos","category-directory-server","category-openldap","tag-centos-8","tag-compiling-openldap-from-source","tag-openldap","tag-openldap-2-4-48","tag-openldap-centos-8","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4731"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=4731"}],"version-history":[{"count":24,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4731\/revisions"}],"predecessor-version":[{"id":21268,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4731\/revisions\/21268"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=4731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=4731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=4731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}