OpenLDAP
OpenLDAP是一套LDAP伺服器软体。
安装
由于OpenLDAP 2.4在2007年十月发行,至今只有一直发行minor release,所以通常都可以透过系统的套件装到合理的版本:
# apt install slapd
另外会安装ldap-utils
,主要是因为CLI下常用的工具不在OpenLDAP内提供,而是透过第三方的方式操作(像是ldapmodify
、ldapdelete
这些指令):
# apt install ldap-utils
设定
Ubuntu 16.04内的版本预设会使用目录结构设定档(预设读取/etc/ldap/slapd.d/
整个目录),但这跟网路上一般使用单档设定不同(通常会是/etc/ldap/slapd.conf
),所以我们要告知slapd使用档案设定档。
这要修改/etc/default/slapd
的内容,将SLAPD_CONF
参数从空的值改为/etc/ldap/slapd.conf
:
# Default location of the slapd.conf file or slapd.d cn=config directory. If
# empty, use the compiled-in default (/etc/ldap/slapd.d with a fallback to
# /etc/ldap/slapd.conf).
SLAPD_CONF=/etc/ldap/slapd.conf
同时我们要将范本复制过来修改(范本在/usr/share/slapd/slapd.conf
这边),里面有一些变数需要设定:
@BACKEND@
设为mdb
。@SUFFIX@
设为dc=example,dc=com
。@ADMIN@
设为cn=Manager,dc=example,dc=com
。
其中的dc=example,dc=com
为范例,可以依照实际组织设定。
另外因为使用mdb,需要将dbconfig
的参数都删除掉(这些是给BerkeleyDB,也就是bdb使用)。
常用指令
这边会列出日常营运常用的指令。其中ldap*
系列指令有一些共通参数:
- 表示操作使用者的
-D
,通常会使用管理员帐号操作,像是-D 'cn=Manager,dc=example,dc=com'
或是-D 'cn=admin,dc=example,dc=com'
。 - 表示base的
-b
,像是-b 'dc=example,dc=com'
。
这些参数可以透过~/.ldaprc
的设定让使用者不需要每次都输入:
BASE dc=example,dc=com BINDDN cn=Manager,dc=example,dc=com
另外密码是每次都得输入的项目:
- 表示操作使用者密码的
-y
,后面接档案名称,像是-y ~/passwd-Manager.txt
。另外一种输入密码的方式为-W
,表示程式执行时手动输入密码。
新增使用者
指令:
$ ldapmodify -x -y ~/passwd-Manager.txt -f user.ldif
对应的LDIF:
dn: uid=${USERNAME},ou=People,dc=example,dc=com changetype: add objectClass: inetOrgPerson cn: ${USERNAME} gn: ${FIRSTNAME} sn: ${LASTNAME} uid: ${USERNAME} userPassword: ${PASSWORD_APR1MD5}