Install and Configure OpenLDAP Server on Ubuntu 20.04
In this blog post you’ll get to figure out how to Install and configure OpenLDAP Server on Ubuntu 20.04 LTS. OpenLDAP is a free and open source execution of the Lightweight Directory Access Protocol created by the OpenLDAP Project and delivered under OpenLDAP Public License.
Set Hostname for Ubuntu
Before beginning of installation, we need to set up hostname for Ubuntu server
$ sudo hostnamectl set-hostname ldap.domain.com
Add IP to the file /etc/hosts
$ vim /etc/hosts
192.168.1.110 ldap.domain.com ldap
Replace domain.com with your hostname or legitimate domain name
Install OpenLDAP Server on Ubuntu
$ sudo apt update $ apt -y slapd ldap-utils
During installation, you will be provoked to set LDAP administrator password.
Affirm the password and proceed.
Affirm your installation while using the command
$ cat slapcat
Add base dn for users and groups
$ vim basedn.ldif dn: ou=people,dc=domain,dc=com objectClass: organizationalUnit ou: people dn: ou=groups,dc=domain,dc=com objectClass: organizationalUnit ou: groups
Replace domain and com with your own domain
Now you can add file by beneath command
$ ldapadd -x -D cn=admin,dc=domain,dc=com -W -f basedn.ldif Enter LDAP Password: adding new entry “ou=people,dc=domain,dc=com” adding new entry “ou=groups,dc=domain,dc=com”
Add User Accounts and Groups
Generate password for user account
$ slappasswd New password: Re-enter new password: {SSHA}Zn4/E5fOrakzaiFY/armlicenseGulHoffmann3x0d
Create ldif file for users
$ vim ldapusers.ldif dn: uid=username,ou=people,dc=domain,dc=com objectClass: inetOrgPerson objectClass: posixAccount objectClass: shadowAccount cn: username sn: Wiz userPassword: {SSHA}Zn4/E5fOrakzaiFY/armlicenseGulHoffmann3x0d loginShell: /bin/bash uidNumber: 1000 gidNumber: 1000 homeDirectory: /home/username
Replace username with original username to add
dc=domain,dc=com with your domain
cn and sn with username
{SSHA}Zn4/E5fOrakzaiFY/armlicenseGulHoffmann3x0d with your hash password
Add account by below command
$ ldapadd -x -D cn=admin,dc=domain,dc=com -W -f ldapusers.ldif Enter LDAP Password: adding new entry “uid=username,ou=people,dc=domain,dc=com”
The same can be done to groups and create ldif file:
$ vim ldapgroups.ldif dn: cn=username,ou=groups,dc=domain,dc=com objectClass: posixGroup cn: username gidNumber: 1000 memberUid: username
Add Group
$ ldapadd -x -D cn=admin,dc=domain,dc=com -W -f ldapgroups.ldif Enter LDAP Password: adding new entry “cn=username,ou=people,dc=domain,dc=com”