centos中ldap怎么配置及使用

在CentOS中配置和使用LDAP,您需要执行以下步骤:

安装OpenLDAP服务器和客户端软件包:

sudo yum install openldap-servers openldap-clients

配置OpenLDAP服务器:

编辑/etc/openldap/slapd.d/cn=config.ldif文件,并添加以下内容:

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=example,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=admin,dc=example,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {CLEARTEXT}password

替换dc=example,dc=com为您自己的域名,并将password替换为您希望设置的管理员密码。

启动OpenLDAP服务器:

sudo systemctl start slapd

创建LDAP数据库:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif

创建LDAP管理员用户:

sudo ldapadd -x -D cn=admin,dc=example,dc=com -W -f admin.ldif

admin.ldif文件中填写以下内容:

dn: cn=admin,dc=example,dc=com
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
userPassword: password
description: LDAP administrator

password替换为您希望设置的管理员密码。

配置LDAP客户端:

编辑/etc/openldap/ldap.conf文件,并添加以下内容:

BASE    dc=example,dc=com
URI     ldap://localhost

dc=example,dc=com替换为您的域名。

测试LDAP连接:

使用以下命令测试LDAP连接是否正常:

ldapsearch -x -b "dc=example,dc=com" -D "cn=admin,dc=example,dc=com" -W

您将被要求输入管理员密码。

这样,您就可以在CentOS中成功配置和使用LDAP了。

阅读剩余
THE END