Configure LDAP Server on CentOS 6

Configure LDAP Server on CentOS 6

Configure LDAP Server on CentOS 6

OpenLDAP logo with green worm mascot

LDAP is an acronym for Lightweight Directory Access Protocol. LDAP is used as a more secure option to NIS. And is the Linux equivalent to Active Directory. OpenLDAP is solid as a rock, and rarely has issues once setup properly, and is an ideal Cross-Platform Directory Server. HOWEVER, OpenLDAP has it’s limitations, i would HIGHLY suggest using 389 Directory Server

Original Reference: http://www.server-world.info/en/note?os=CentOS_6&p=ldap&f=1

the LDAP domain we are setting up will be: dc=mydomain,dc=com

Let’s Get Started! Login, and su to root

Root shell prompt on host LDAPDEMO

from here install the necessary tools/dependencies

yum -y install openldap-servers openldap-clients

from here tell ldap to start on startup, and start the service

chkconfig slapd on and service slapd start, Starting slapd OK

now edit the following config file:

vi /etc/sysconfig/ldap on LDAPDEMO

edit line 16 so that SLAPD_LDAPS=yes

/etc/sysconfig/ldap with SLAPD_LDAPS=yes set to enable LDAPS

now edit the slapd.conf

vi /etc/openldap/slapd.conf to create a new file

add the following lines to the new blank file:

New slapd.conf lines, pidfile /var/run/openldap/slapd.pid and argsfile /var/run/openldap/slapd.args

remove all the default clutter in /etc/openldap/slapd.d/*

rm -rf /etc/openldap/slapd.d/* to clear the default config

now run a slaptest (to me that’s just funny…)

slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d: config file testing succeeded

edit the following file:

vi the cn=config olcDatabase={0}config.ldif file under /etc/openldap/slapd.d

edit to match this line exactly

olcDatabase={0}config.ldif with the olcAccess line granting manage to gidNumber=0+uidNumber=0 via EXTERNAL auth

now we need to edit the next config

vi the cn=config olcDatabase={1}monitor.ldif file

copy/paste the following:

dn: olcDatabase={1}monitor
objectClass: olcDatabaseConfig
olcDatabase: {1}monitor
olcAccess: {1}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break
olcAddContentAcl: FALSE
olcLastMod: TRUE
olcMaxDerefDepth: 15
olcReadOnly: FALSE
olcMonitoring: FALSE
structuralObjectClass: olcDatabaseConfig
creatorsName: cn=config
modifiersName: cn=config

From here set the permissions, and start LDAP

chown -R ldap. and chmod -R 700 /etc/openldap/slapd.d, then /etc/rc.d/init.d/slapd start OK

now onto the actual LDAP Domain Configuration. Start with Part1

ldapadd -Y EXTERNAL -H ldapi:/// -f core.ldif: adding new entry cn=core,cn=schema,cn=config

now part 2

ldapadd of cosine.ldif, adding new entry cn=cosine,cn=schema,cn=config

part 3

ldapadd of nis.ldif, adding new entry cn=nis,cn=schema,cn=config

part 4

ldapadd of inetorgperson.ldif, adding new entry cn=inetorgperson,cn=schema,cn=config

from here we need to generate our LDAP admin password:

slappasswd prompting twice and printing a {SSHA} password hash

copy/paste this to a safe location, it will need to be used again

change directory

cd /etc/openldap/slapd.d

from here we need to create/edit the back-end database

vi backend.ldif at the root prompt

copy/paste the following

dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib64/openldap
olcModuleload: back_hdb

dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
olcSuffix: dc=server,dc=world
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=server,dc=world
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcMonitoring: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword by dn="cn=admin,dc=server,dc=world" write by anonymous auth by self write by * none
olcAccess: to attrs=shadowLastChange by self write by * read
olcAccess: to dn.base="" by * read
olcAccess: to * by dn="cn=admin,dc=server,dc=world" write by * read

In here we need to edit our oclRootPW (enter the SSHA generated earlier), as well as change the dc=server,dc=world to dc=mydomain,dc=com, there is a total of 4 domain replacements in this file.

now add the info to the LDAP database

ldapadd of backend.ldif, adding cn=module,cn=config and olcDatabase=hdb,cn=config

now we need to create/edit the frontend

vi frontend.ldif at the root prompt

please make sure to edit lines 6, and 7 to match the dc=server,dc=world

dn: dc=server,dc=world
objectClass: top
objectClass: dcObject
objectclass: organization
o: Server World
dc: Server

dn: cn=admin,dc=server,dc=world
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
userPassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx

dn: ou=people,dc=server,dc=world
objectClass: organizationalUnit
ou: people

dn: ou=groups,dc=server,dc=world
objectClass: organizationalUnit
ou: groups

From here we need to again copy/paste the SSHA to replace the default config. We also need to replace dc=server,=dc=world with dc=mydomain,dc=com. There is a total of 4 replacements in this file as well.

now commit the frontend to the database

ldapadd -x -D cn=admin,dc=mydomain,dc=com -W -f frontend.ldif adding base, admin, people and groups entries

restart LDAP, and you are in business

service slapd restart, Stopping slapd OK, Starting slapd OK

from here if you use ldapadd/ldapmodify, you will need to click here

That’s it, you have successfully configured LDAP on CentOS.

  • To configure phpLDAPadmin click here
  • To configure LDAP Master/Slave Replication Click here
  • To configure LDAP over TLS/SSL click here
  • To Configure LDAP Logging click here
  • To Authenticate Windows 7 Against LDAP click here
  • To configure your LDAP server as an internal DNS server click here
  • To configure your LDAP server as a DHCP server click here
  • To configure your LDAP server as a NTP server click here

Hosted Linux Servers at www.zwiegnet.com/go

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *