Skip to content

LDAP 部署和使用

LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是一种用于访问和维护分布式目录信息服务的开放标准协议。它通常用于组织、管理和访问网络中的用户、计算机、打印机等资源的信息。LDAP 基于 X.500 标准,但比 X.500 更简单、更轻量级,适用于各种网络环境。

官方链接:https://www.openldap.org/

Docker image to run OpenLDAP: https://github.com/osixia/docker-openldap

启动服务

最新启动方式可以参考上方提供的 Docker image。

docker run -p 389:389 -p 636:636 --name my-openldap-container --detach osixia/openldap:1.5.0

常用命令

新增

创建用户/配置文件如下(user.ldif):

dn: uid=billy,dc=example,dc=org
uid: billy
cn: billy
sn: 3
objectClass: top
objectClass: posixAccount
objectClass: inetOrgPerson
loginShell: /bin/bash
homeDirectory: /home/billy
uidNumber: 14583102
gidNumber: 14564100
userPassword: billyp

userPassword 支持形式:

官方文档:https://www.openldap.org/faq/data/cache/347.html

shell
# plain text
userPassword: mypassword

# base64 encoded
userPassword:: e1NIQX1mRFlIdU9ZYnp4bEU2ZWhRT21ZUElmUzI4L0U9

# hash
userPassword: {SHA}fDYHuOYbzxlE6ehQOmYPIfS28/E=

# hash with base64
userPassword: {SSHA}e1NIQX1mRFlIdU9ZYnp4bEU2ZWhRT21ZUElmUzI4L0U9

命令:

docker exec my-openldap-container ldapadd -x -H ldap://localhost -D "cn=admin,dc=example,dc=org" -w admin -f user.ldif

查询

docker exec my-openldap-container ldapsearch -x -H ldap://localhost -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin

删除

docker exec my-openldap-container ldapdelete -x -H ldap://localhost -D "cn=admin,dc=example,dc=org" -w admin uid=billy,dc=example,dc=org