Open Ldap
Open Ldap
ldif
by:
ldapadd -x -w redhat -D cn=Manager,dc=example,dc=com -f /etc/openldap/base.ldif
[1]
Install OpenLDAP Server.
[root@dlp ~]# yum -y install openldap-servers openldap-clients
[root@dlp ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_
CONFIG
[root@dlp ~]# chown ldap. /var/lib/ldap/DB_CONFIG
[root@dlp ~]# systemctl start slapd
[root@dlp ~]# systemctl enable slapd
[2]
[1]
Add a user.
# generate encrypted password
[root@dlp ~]# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxx
[root@dlp ~]# vi ldapuser.ldif
# create new
# replace to your own domain name for "dc=***,dc=***" section
dn: uid=cent,ou=People,dc=server,dc=world
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: Cent
sn: Linux
userPassword: {SSHA}xxxxxxxxxxxxxxxxx
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/cent
dn: cn=cent,ou=Group,dc=server,dc=world
objectClass: posixGroup
cn: Cent
gidNumber: 1000
memberUid: cent
[root@dlp ~]# ldapadd -x -D cn=Manager,dc=server,dc=world -W -f ldapuser.ldif
Enter LDAP Password:
adding new entry "uid=cent,ou=People,dc=server,dc=world"
adding new entry "cn=cent,ou=Group,dc=server,dc=world"
[2]
Add users and groups in local passwd/group to LDAP directory.
[root@dlp ~]# vi ldapuser.sh
# extract local users and groups who have 1000-9999 digit UID
# replace "SUFFIX=***" to your own domain name
# this is an example
#!/bin/bash
SUFFIX='dc=server,dc=world'
LDIF='ldapuser.ldif'
echo -n > $LDIF
GROUP_IDS=()
grep "x:[1-9][0-9][0-9][0-9]:" /etc/passwd | (while read TARGET_USER
do
USER_ID="$(echo "$TARGET_USER" | cut -d':' -f1)"
USER_NAME="$(echo "$TARGET_USER" | cut -d':' -f5 | cut -d' ' -f1,2)"
[ ! "$USER_NAME" ] && USER_NAME="$USER_ID"
LDAP_SN="$(echo "$USER_NAME" | cut -d' ' -f2)"
adding
adding
adding
adding
adding
adding
adding
adding
new
new
new
new
new
new
new
new
entry
entry
entry
entry
entry
entry
entry
entry
"uid=cent,ou=People,dc=server,dc=world"
"uid=redhat,ou=People,dc=server,dc=world"
"uid=ubuntu,ou=People,dc=server,dc=world"
"uid=debian,ou=People,dc=server,dc=world"
"cn=cent,ou=Group,dc=server,dc=world"
"cn=redhat,ou=Group,dc=server,dc=world"
"cn=ubuntu,ou=Group,dc=server,dc=world"
"cn=debian,ou=Group,dc=server,dc=world"
[3]
If you'd like to delete LDAP User or Group, Do as below.
[root@dlp ~]# ldapdelete -x -W -D 'cn=Manager,dc=server,dc=world' "uid=cent,ou=P
eople,dc=server,dc=world"
Enter LDAP Password:
[root@dlp ~]# ldapdelete -x -W -D 'cn=Manager,dc=server,dc=world' "cn=cent,ou=Gr
oup,dc=server,dc=world"
Enter LDAP Password: