SASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\nadding new entry \"olcDatabase=mdb,cn=config\"<\/code><\/pre>\n\n\n\nTo secure OpenLDAP communication between the client and the server, configured it to use SSL\/TLS certificates.<\/p>\n\n\n\n
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
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \\\n\/etc\/ssl\/ldapserver.key -out \/etc\/ssl\/ldapserver.crt<\/code><\/pre>\n\n\n\nchown ldap:ldap \/etc\/ssl\/{ldapserver.crt,ldapserver.key}<\/code><\/pre>\n\n\n\nUpdate the OpenLDAP Server TLS certificates attributes.<\/p>\n\n\n\n
\ncat > tls.ldif << 'EOL'\ndn: cn=config\nchangetype: modify\nadd: olcTLSCACertificateFile\nolcTLSCACertificateFile: \/etc\/ssl\/ldapserver.crt\n-\nadd: olcTLSCertificateFile\nolcTLSCertificateFile: \/etc\/ssl\/ldapserver.crt\n-\nadd: olcTLSCertificateKeyFile\nolcTLSCertificateKeyFile: \/etc\/ssl\/ldapserver.key\nEOL\n<\/code><\/pre>\n\n\n\nNote that we have used self-signed certificate as both the certificate and the CA certificate.<\/p>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f tls.ldif<\/code><\/pre>\n\n\n\nYou can confirm this by running;<\/p>\n\n\n\n
slapcat -b \"cn=config\" | grep olcTLS<\/code><\/pre>\n\n\n\nolcTLSCACertificateFile: \/etc\/ssl\/ldapserver.crt\nolcTLSCertificateFile: \/etc\/ssl\/ldapserver.crt\nolcTLSCertificateKeyFile: \/etc\/ssl\/ldapserver.key<\/code><\/pre>\n\n\n\nChange the location of the CA certificate on \/etc\/ldap\/ldap.conf<\/code>.<\/p>\n\n\n\nsed -i 's|\/etc\/ssl\/certs\/ca-certificates.crt|\/etc\/ssl\/ldapserver.crt|' \/etc\/ldap\/ldap.conf<\/code><\/pre>\n\n\n\nCreate OpenLDAP Base DN<\/h4>\n\n\n\n
Next, create your base DN or search base to define your organization structure and directory.<\/p>\n\n\n\n
Replace the domain components and organization units accordingly.<\/p>\n\n\n\n
\ncat > basedn.ldif << 'EOL'\ndn: 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\nEOL\n<\/code><\/pre>\n\n\n\nldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f basedn.ldif<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
...\nadding new entry \"dc=ldapmaster,dc=kifarunix-demo,dc=com\"\n\nadding new entry \"ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\"\n\nadding new entry \"ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\"<\/code><\/pre>\n\n\n\nCreate OpenLDAP User Accounts<\/h4>\n\n\n\n
You can add users to your OpenLDAP server. Create an ldif file to define your users as follows.<\/p>\n\n\n\n
\ncat > users.ldif << 'EOL'\ndn: 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\nEOL\n<\/code><\/pre>\n\n\n\nAdd the user to the OpenLDAP database.<\/p>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f users.ldif<\/code><\/pre>\n\n\n\nSetting password for LDAP User<\/h4>\n\n\n\n
To set the password for user above, run the command below;<\/p>\n\n\n\n
ldappasswd -H ldapi:\/\/\/ -Y EXTERNAL -S \"uid=johndoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\"<\/code><\/pre>\n\n\n\nCreate OpenLDAP Bind DN and Bind DN User<\/h4>\n\n\n\n
Bind DN user is used for performing LDAP operations such as resolving User IDs and group IDs.<\/p>\n\n\n\n
In this guide, we create a bind DN ou called system<\/code>.<\/p>\n\n\n\n