ldapsearch 命令详解:搜索 LDAP 目录服务器指南
ldapsearch 命令详解:搜索 LDAP 目录服务器指南
ldapsearch 是一个强大的命令行工具,用于搜索 LDAP 目录服务器中的条目。本指南将带您了解 ldapsearch 的基本语法、常用选项、过滤器示例,以及如何使用它连接到 LDAP 服务器并执行搜索。
基本语法
ldapsearch 的基本语法如下:
ldapsearch [options] [filter]
options:可选参数,用于控制搜索行为。filter:LDAP 过滤器,用于指定搜索条件。
常用选项
以下是一些常用的 ldapsearch 选项:
| 选项 | 描述 |
|---|---|
| -h | 指定 LDAP 服务器的主机名或 IP 地址。 |
| -p | 指定 LDAP 服务器的端口号。 |
| -D | 指定用于身份验证的 LDAP 绑定 DN。 |
| -w | 指定 LDAP 绑定 DN 的密码。 |
| -b | 指定要搜索的 LDAP 目录的基本 DN。 |
| -s | 指定搜索的范围(base、one、sub)。 |
| -a | 指定搜索结果的输出格式(base、one、sub)。 |
LDAP 过滤器
LDAP 过滤器用于指定搜索条件。以下是一些常用的 LDAP 过滤器:
(objectClass=*):返回所有条目。(objectClass=inetOrgPerson):返回所有inetOrgPerson条目。(cn=John Smith):返回cn为 'John Smith' 的条目。(&(objectClass=inetOrgPerson)(cn=John Smith)):返回objectClass为inetOrgPerson且cn为 'John Smith' 的条目。
搜索示例
例如,要搜索 cn 为 'John Smith' 的 inetOrgPerson 条目,可以使用以下命令:
ldapsearch -h ldap.example.com -p 389 -D 'cn=admin,dc=example,dc=com' -w password -b 'dc=example,dc=com' -s sub '(objectClass=inetOrgPerson)(cn=John Smith)'
该命令将连接到 ldap.example.com 的 LDAP 服务器,使用 cn=admin,dc=example,dc=com 进行身份验证,搜索 dc=example,dc=com 下所有 inetOrgPerson 条目,并返回 cn 为 'John Smith' 的条目。
总结
ldapsearch 是一个功能强大的工具,可用于搜索 LDAP 目录服务器。通过理解其语法、选项和过滤器,您可以轻松地找到所需的信息。
原文地址: https://www.cveoy.top/t/topic/jxIp 著作权归作者所有。请勿转载和采集!