How to Configure SUDO access via OpenLDAP Server<\/a><\/p>\n\n\n\nCreate OpenLDAP User Accounts<\/h3>\n\n\n\n
Before we can create OpenLDAP user accounts, we need to create the organization unit containers for storing users and their group information. See our example below. Be sure to make the relevant changes as per your environment setup.<\/p>\n\n\n\n
vim users-ou.ldif<\/code><\/pre>\n\n\n\ndn: ou=people,dc=kifarunix-demo,dc=com\nobjectClass: organizationalUnit\nobjectClass: top\nou: people\n\ndn: ou=groups,dc=kifarunix-demo,dc=com\nobjectClass: organizationalUnit\nobjectClass: top\nou: groups\n<\/code><\/pre>\n\n\n\nBefore you can be able to update the database with the users OU information above, you need to adjust the SLAPD database access controls;<\/p>\n\n\n\n
vim update-mdb-acl.ldif<\/code><\/pre>\n\n\n\ndn: olcDatabase={1}mdb,cn=config\nchangetype: modify\nreplace: olcAccess\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.exact=\"cn=readonly,ou=people,dc=kifarunix-demo,dc=com\" read \n by * none\nolcAccess: to dn.exact=\"cn=readonly,ou=people,dc=kifarunix-demo,dc=com\" by dn.subtree=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\" manage by * none\nolcAccess: to dn.subtree=\"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\n<\/code><\/pre>\n\n\n\nSave and exit the file.<\/p>\n\n\n\n
Note that we have included the access controls for the Read Only Bind DN user that we will create later in this guide.<\/p>\n\n\n\n
Update database ACL with the above information by running the command below;<\/p>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f update-mdb-acl.ldif<\/code><\/pre>\n\n\n\nOnce that is done, you should now be able, as the admin, to create the users OU as shown above. Therefore, to update the database with the user OU information above, run the command below;<\/p>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f users-ou.ldif<\/code><\/pre>\n\n\n\n...\nadding new entry \"ou=people,dc=kifarunix-demo,dc=com\"\nadding new entry \"ou=groups,dc=kifarunix-demo,dc=com\"<\/strong><\/code><\/pre>\n\n\n\nOnce you have the user OU containers created, you can now add user accounts. In this demo, we will create a user called johndoe<\/strong> in our OpenLDAP database.<\/p>\n\n\n\nvim johndoe.ldif<\/code><\/pre>\n\n\n\ndn: uid=johndoe,ou=people,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=kifarunix-demo,dc=com\nobjectClass: posixGroup\ncn: johndoe\ngidNumber: 10000\nmemberUid: johndoe\n<\/code><\/pre>\n\n\n\nTo add the user johndoe to the database using the information above, run the command below;<\/p>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f johndoe.ldif<\/code><\/pre>\n\n\n\nadding new entry \"uid=johndoe,ou=people,dc=kifarunix-demo,dc=com\"\nadding new entry \"cn=johndoe,ou=groups,dc=kifarunix-demo,dc=com\"<\/code><\/pre>\n\n\n\nSetting Password for LDAP User<\/h4>\n\n\n\n
If you noticed, in the above, we didn’t set any password for the user. To set\/reset the password for the user, run the command below;<\/p>\n\n\n\n
ldappasswd -H ldapi:\/\/\/ -Y EXTERNAL -S \"uid=johndoe,ou=people,dc=kifarunix-demo,dc=com\"<\/code><\/pre>\n\n\n\nTo verify user’s password;<\/p>\n\n\n\n
ldapwhoami -h ldap.kifarunix-demo.com -x -D \"uid=johndoe,ou=people,dc=kifarunix-demo,dc=com\" -W<\/code><\/pre>\n\n\n\nIf the password is correct, you should see the user’s DN;<\/p>\n\n\n\n
dn:uid=johndoe,ou=people,dc=kifarunix-demo,dc=com<\/code><\/pre>\n\n\n\nCreate OpenLDAP BIND DN<\/h3>\n\n\n\n
There are two OpenLDAP BIND DNs;<\/p>\n\n\n\n
\nAdministrator Bind DN<\/strong><\/code>: defines admin username and password. It is used only for querying the directory server and so this user must have privileges to search the directory.<\/li>\n\n\n\nUser Bind DN<\/strong><\/code>: defines the user username and password is used for authentication and password change operations.<\/li>\n<\/ul>\n\n\n\nIn this demo, we will create a user Bind DN called readonly<\/strong><\/code> for read operations.<\/p>\n\n\n\n