Everything is identified by dn
cn= Common Name
ou= Organizational Unit
dc= Domain Component
Schemas, objectClasses and Attributes
An objectClass is a collection of attributess:
- An objectclass is defined within a Schema
- An objectclass may be a part of an objectclass hierarchy, in which case it inherits all the properties of its parents.
- An objectclass has a globally unique name or identifier
Attributes typically contain data:
- Every attribute is defined in a schema.
- Every attribute is included in one or moreobjectclasses.
- To use an attribute in an entry, itsobjectclass must be included in the entry definition and its objectclass must be included in a schema. In turn, the schema must be identified to the LDAP server.
Install LDAP
apt-get install slapd ldap-utils ldapvi
Config Layout
Setup backend database
Import schemas
$ cd /etc/ldap/schema
$ ldapadd -Y EXTERNAL -H ldapi:/// -f cosine.ldif
$ ldapadd -Y EXTERNAL -H ldapi:/// -f nis.ldif
(Provides linux account attributes)
$ ldapadd -Y EXTERNAL -H ldapi:/// -f inetorgperson.ldif
backend.ldif
# Load dynamic backend modulesdn: cn=module,cn=configobjectClass: olcModuleListcn: moduleolcModulepath: /usr/lib/ldapolcModuleload: back_hdb.la
# Database Settingdn: olcDatabase={1}hdb,cn=configobjectClass: olcDatabaseConfigobjectClass: olcHdbConfigolcDatabase: {1}hdbolcSuffix: dc=[ID],dc=csie,dc=ntu,dc=edu,dc=twolcDbDirectory: /var/lib/ldapolcRootDN: cn=admin,dc=[ID],dc=csie,dc=ntu,dc=edu,dc=twolcRootPW: {SSHA}HUpwPlcpSOwCNd8hRfiQsXFYYdyPewC2**olcDbConfig: set_cachesize 0 2097152 0olcDbConfig: set_lk_max_objects 1500olcDbConfig: set_lk_max_locks 1500olcDbConfig: set_lk_max_lockers 1500olcDbIndex: objectClass eqolcLastMod: TRUEolcDbCheckpoint: 512 30olcAccess: to attrs=userPassword,shadowLastChange by dn="cn=admin,dc=[ID],dc=csie,dc=ntu,dc=edu,dc=tw" write by anonymous auth by self write by * noneolcAccess: to attrs=homeDirectory by dn="cn=admin,dc=[ID],dc=csie,dc=ntu,dc=edu,dc=tw" write by anonymous auth by self read by * noneolcAccess: to dn.base="" by * readolcAccess: to * by dn="cn=admin,dc=fate,dc=csie,dc=ntu,dc=edu,dc=tw" write by * read
**note:olcrootPW generated by
slappasswdimport backend
ldapadd -v -Y EXTERNAL -H ldapi:/// -f backend.ldifFRONTEND: Adding users and groups (by ldapscripts or frontend.ldif file)
for /etc/passwd
objectClass: posixAccount
id uid
password userPassword
uid uidNumber
gid gidNumber
full_name gecos
Home Directory homeDirectory
Login shell loginShell
for /etc/shadow
objectClass: shadowAccount
username uid
password userPassword
last shadowLastChange
may shadowMin
must shadowMax
warn shadowWarning
expire shadowExpire
disable shadowInactive
reserved shadowFlag
for /etc/group
objectClass: posixGroup
group name cn
password userPassword
group id gidNumber
other account memberUid
| objectClass: posixAccount | |
| id | uid |
| password | userPassword |
| uid | uidNumber |
| gid | gidNumber |
| full_name | gecos |
| Home Directory | homeDirectory |
| Login shell | loginShell |
| objectClass: shadowAccount | |
| username | uid |
| password | userPassword |
| last | shadowLastChange |
| may | shadowMin |
| must | shadowMax |
| warn | shadowWarning |
| expire | shadowExpire |
| disable | shadowInactive |
| reserved | shadowFlag |
| objectClass: posixGroup | |
| group name | cn |
| password | userPassword |
| group id | gidNumber |
| other account | memberUid |
option 1: Use ldapscripts to add user
install ldapscripts(which includes utilities too add/remove POSIX accounts)
apt-get isntall ldapscripts modify /etc/ldapscripts/ldapscripts.conf
SERVER=localhost
BINDDN='cn=admin,dc=,dc=csie,dc=ntu,dc=edu,dc=tw'
SUFFIX='dc=,dc=csie,dc=ntu,dc=edu,dc=tw'
GSUFFIX='ou=Groups'
USUFFIX='ou=Peolple'
MSUFFIX='ou=machines'
GIDSTART=10000
UIDSTART=10000
MIDSTART=10000
PASSWORDGEN="pwgen" // $ apt-get install pwgen
RECORDPASSWORDS="yes"
PASSWORDFILE="/var/log/ldapscripts_passwd.log"
BINDPWDFILE="/etc/ldapscripts/ldapscripts.passwd"
keep the rootPW in /etc/ldapscripts/ldapscripts.passwd
sh -c "echo -n '[password]' > /etc/ldapscripts/ldapscripts.passwd"
chmod 400 /etc/ldapscripts/ldapscripts.passwd
**Careful: if authentication failure happens after ldapadduser. Check LDAP database for user password encryption
try dpkg-reconfigure libpam-ldap and set encryption methodOption 2: use frontend.ldif
file frontend.ldif
# Create top-level object in domain
dn: dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=twobjectClass: top
objectClass: dcObject
objectclass: organization
o: b99902120
dc: b99902120
description: b99902120
#people
dn: ou=people,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw objectClass: organizationalUnit
ou: people
#groups
dn: ou=groups,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=twobjectClass: organizationalUnit
ou: groups
#user setting: ta217, groups, b99902120.csie.ntu.edu.tw
dn: uid=ta217,ou=people,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=twobjectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: ta217
displayName: ta217
uidNumber: 1001
gidNumber: 1001
userPassword: SAL2013
gecos: ta217
loginShell: /bin/bash
homeDirectory: /home/ta217
shadowExpire: -1
shadowFlag: 0
shadowWarning: 7
shadowMin: 8
shadowMax: 999999
shadowLastChange: 10877
givenName: 217
sn: ta
cn: ta217
mail: ta217@b99902120.csie.ntu.edu.tw
title: ta217
#group setting: ta217, groups, b99902120.csie.ntu.edu.tw
dn: cn=ta217,ou=groups,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=twobjectClass: posixGroup
cn: ta217
gidNumber: 1001
import frontend file ldapadd -v -x -D -W -f frontend.ldif nss and pam
apt-get install libpam-ldap libnss-ldap libnss-db nslcd nscd/etc/libnss-ldap.conf
base dc="dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw"
/etc/nsswitch.conf
passwd: files ldap
group: files ldap
shadow: files ldapadd users and groups
ldapadduser [user] [group]ldapaddgroup [group]update pam auth
pam-auth-updateauto create home directory
/etc/pam.d/common-account
session required pam_mkhomedir.so skel=/etc/skel/ umask=0022
Allow user change password
vim /etc/pam.d/common-password
password [success=1 user_unknown=ignore default=die]
pam_ldap.so use_authtok try_first_pass
change to
password [success=1 user_unknown=ignore default=die]
pam_ldap.so try_first_pass
client config
/etc/nslcd.conf
# The user and group nslcd should run as.
uid nslcd
gid nslcd
# The location at which the LDAP server(s) should be reachable.
uri ldap://192.168.50.119
# The search base that will be used for all queries.
base dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
/etc/nsswitch.conf
passwd: files ldap
group: files ldap
shadow: files ldap