Home / Articles / Linux / authentication / 7 / openldap

Configure OpenLDAP

Configure OpenLDAP Server

  1. Install OpenLDAP-Server RPM
  2. Use yum to install following rpm's.

    # yum -y install openldap openldap-servers openldap-clients

    Start and enable openldap-server deamon

    # systemctl start slapd.service # systemctl enable slapd.service Created symlink from /etc/systemd/system/multi-user.target.wants/slapd.service to /usr/lib/systemd/system/slapd.service.
  3. Set LDAP root account password and generate hash
  4. Run slappasswd and set LDAP root password and generate its Hash. Keep a note of both the password and its hash as these will be used later in configurations

    # slappasswd New password: Re-enter new password: {SSHA}JNNjNtlq2ZtO7oDvcR+7YbTuOvx8nv5V
  5. Add LDAP server initial configuration Attribute
  6. Create base_config.ldif file with following contents:

    # vi base_config.ldif dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcSuffix olcSuffix: dc=linuxtechspace,dc=com dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcRootDN olcRootDN: cn=root,dc=linuxtechspace,dc=com dn: olcDatabase={2}hdb,cn=config changeType: modify add: olcRootPW olcRootPW: {SSHA}JNNjNtlq2ZtO7oDvcR+7YbTuOvx8nv5V 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=root,dc=linuxtechspace,dc=com" read by * none

    Deploy configuration change to LDAP server.

    # ldapmodify -Y EXTERNAL -H ldapi:/// -f base_config.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 modifying entry "olcDatabase={2}hdb,cn=config" modifying entry "olcDatabase={2}hdb,cn=config" modifying entry "olcDatabase={2}hdb,cn=config" modifying entry "olcDatabase={1}monitor,cn=config"
  7. Add in-built LDAP schemas
  8. # 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
  9. Set LDAP Domain Attribute
  10. Create create_domain.ldif file with following contents:

    # vi create_domain.ldif dn: dc=linuxtechspace,dc=com objectClass: dcObject objectClass: organization dc: linuxtechspace o: linuxtechspace dn: ou=users,dc=linuxtechspace,dc=com objectClass: organizationalUnit ou: users

    Deploy configuration change to LDAP server.

    # ldapadd -x -W -D cn=root,dc=linuxtechspace,dc=com -f create_domain.ldif Enter LDAP Password: adding new entry "dc=linuxtechspace,dc=com" adding new entry "ou=users,dc=linuxtechspace,dc=com"

    Enter the LDAP root account password when prompted which we set in initial steps.

  11. Adding LDAP User
  12. Create ldap password for sample test user

    # slappasswd New password: Re-enter new password: {SSHA}r/xCHez+Sik4Y7TfirPDVXdsWuD7+Kd4

    Create create_test_user.ldif file with following contents:

    # vi create_test_user.ldif dn: uid=test,ou=users,dc=linuxtechspace,dc=com uid: test cn: test objectClass: shadowAccount objectClass: top objectClass: person objectClass: inetOrgPerson objectClass: posixAccount userPassword: {SSHA}r/xCHez+Sik4Y7TfirPDVXdsWuD7+Kd4 shadowLastChange: 17016 shadowMin: 0 shadowMax: 99999 shadowWarning: 7 loginShell: /bin/bash uidNumber: 1002 gidNumber: 1002 homeDirectory: /home/test sn: test dn: cn=test,ou=users,dc=linuxtechspace,dc=com objectClass: posixGroup objectClass: top cn: test userPassword: {crypt}x gidNumber: 1002

    Deploy configuration change to LDAP server.

    # ldapadd -x -W -D cn=root,dc=linuxtechspace,dc=com -f create_test_user.ldif Enter LDAP Password: adding new entry "uid=test,ou=users,dc=linuxtechspace,dc=com" adding new entry "cn=test,ou=users,dc=linuxtechspace,dc=com"

    Enter the LDAP root account password when prompted which we set in initial steps.

View OpenLDAP Server Configuration

  1. Check DB File Config
  2. # ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config olcDatabase=\*
  3. Check Domain Config
  4. # ldapsearch -x -b dc=linuxtechspace,dc=com
  5. Check User Config
  6. # ldapsearch -x -b "dc=linuxtechspace,dc=com" "(cn=test)"

OpenLDAP Client Configuration

  • Install OpenLDAP Client RPM
  • # yum -y install openldap openldap-clients nss-pam-ldapd nscd
  • Enable LDAP Client Configuration
  • # authconfig --enableldap --enableldapauth --ldapserver=openldap-server:389 \ --ldapbasedn="dc=linuxtechspace,dc=com" --enablemkhomedir --update

    Replace openldap-server with your ldap server hostname

  • Verify nsswitch Setting
  • Check /etc/nsswitch.conf file to make sure ldap option is configured for following three parameters

    # vi /etc/nsswitch.conf passwd: files sss ldap shadow: files sss ldap group: files sss ldap
  • Start and Enable NSCD Services
  • # systemctl start nscd nslcd # systemctl enable nscd nslcd
  • Query test user information from LDAP Server
  • # getent passwd test test:x:1002:1002:test:/home/test:/bin/bash
  • Login to server with test user. User home directory will be auto-created
  • login as: test test@openldap-client's password: Creating directory '/home/test'. [test@openldap-client ~]$