西风古道

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

CentOS6.8 min

OpenLDAP 2.4.40

 

shell>yum install openldap*    //直接使用yum方式安装

shell>iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 389 -j ACCEPT  //开启OpenLdap服务389端口

 

//复制一份DB数据库配置文件至OpenLDAP数据库所在目录,并更改所有者及群组

shell>cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

shell>service slapd start

shell>chown -R ldap.ldap /var/lib/ldap

 

//修改主配置文件,并根据此配置文件生成工作目录

shell>cd /etc/openldap

shell>cp /usr/share/openldap-servers/slapd.conf.obsolete slapd.conf

shell>slappasswd

将生成的密文保存下来{SSHA}KfKXTrXgnLlbl5n4UcbZ8kh9V7KiMUoj

shell>vi /etc/openldap/slapd.conf

红色需要注意的地方。

......
database monitor
access to *
        by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
        by dn.exact="cn=admin,dc=mydomain,dc=com" read
        by * none
......
database        bdb
suffix          "dc=mydomain,dc=com"
checkpoint      1024 15
rootdn          "cn=admin,dc=mydomain,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoided.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
# rootpw                secret
# rootpw                {crypt}ijFYNcSNctBYg
rootpw                  {SSHA}KfKXTrXgnLlbl5n4UcbZ8kh9V7KiMUoj

shell>rm -rf /etc/openldap/slapd.d/*     //删除原有的工作目录文件,使用slaptest来生成一份新的

shell>slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d

shell>chown -R ldap.ldap /etc/openldap/slapd.d

shell>service slapd restart

shell>chkconfig slapd on

//安装结束。

 

导入一个根节点

shell>vim base.ldif

dn: dc=mydomain,dc=com
objectclass: dcObject
objectclass: organization
o: mydomain
dc: mydomain

shell>ldapadd -x -W -D "cn=admin,dc=mydomain,dc=com" -f base.ldif

shell>ldapsearch -x -W -D "cn=admin,dc=mydomain,dc=com" -b "dc=mydomain,dc=com"

 

安装phpLDAPadmin来操作OpenLDAP

phpLDAPadmin官方:http://sourceforge.net/projects/phpldapadmin/

下载后

shell>unzip phpldapadmin-version.zip -d /tmp/

安装所需环境

shell>yum install httpd php php-ldap

shell>mv /tmp/phpldapadmin /var/www/html/

shell>mv /var/www/html/phpldapadmin/config/config.php.example /var/www/html/phpldapadmin/config/config.php

此配置文件可不修改直接使用

shell>service httpd start

此后可使用浏览器来访问,比如:http://ip/phpldapadmin,如远程的不要忘了开放80端口。

 

下面是一些关于acl的权限控制

shell>vi /etc/openldap/slapd.conf

这些是基于上面的设置进行控制,一般用户只能看到自身,自己只能修改自己密码
access to dn.base="" by * read
access to dn.base="cn=Subschema" by * read
access to dn.base="dc=mydomain,dc=com" by * read
access to dn.base="ou=People,dc=mydomain,dc=com" by * read
access to attrs=userPassword     //此权限要在自身可读权限的前面
        by self write
        by anonymous auth
access to dn.children="ou=People,dc=mydomain,dc=com" //用户只能看到自己的信息
        by self read
        by anonymous auth

 

以下是关于Samba使用OpenLDAP来验证用户

如果只是使用OpenLDAP的用户信息不使用登陆系统,那么只需要安装nslcd服务,不需要安装pam_ldap模块。

shell>yum install nss-pam-ldapd

shell>authconfig-tui

如果OpenLDAP对用户的权限做了限制,比如不能使用匿名用户来读取用户信息,那么需要配置nslcd

shell>vi /etc/nslcd.conf

binddn cn=admin,dc=mydomain,dc=com
bindpw rootdn的密码

shell>service nslcd restart

shell>id test   //如果OpenLDAP中有一用户test,那么现在就能看到test用户的信息了

 

现在配置samba:

shell>vim /etc/samba/smb.conf

。。。
        passdb backend = ldapsam:ldap://OpenLDAP_ip //注释原来的配置
        ldap admin dn = "cn=admin,dc=mydomain,dc=com"
        ldap suffix = dc=helilv,dc=cn
        ldap user suffix = ou=People
        ldap delete dn = no
        ldap ssl = off
        encrypt passwords = true
。。。

shell>smbpass -w dnroot的密码   //将OpenLDAP的管理员密码导入samba的数据库中

shell>service smb restart

正常重启后,此时在OpenLDAP中,会自动生成一条domain信息

sambaDomainName=XXXXX

未生成这条记录,配置有误!

 shell>smbpasswd -a test       //添加 samba用户

基本上就是这样配置的。

 

以下是用作系统登陆:

需要加入 pam_ldap 模块

shell>yum install pam_ldap

与nslcd服务一样,如果匿名用户不能读取用户信息,需要配置管理员信息

shell>vi /etc/pam_ldap.conf

 

备份:

shell> ldapsearch -LLL -x -W -D "cn=admin,dc=mydomain,dc=com" -b "dc=mydomain,dc=com" > ldapbackup.ldif

 

For example, if the directory contained entries named:

        0: o=suffix
        1: cn=Manager,o=suffix
        2: ou=people,o=suffix
        3: uid=kdz,ou=people,o=suffix
        4: cn=addresses,uid=kdz,ou=people,o=suffix
        5: uid=hyc,ou=people,o=suffix
Then:

dn.base="ou=people,o=suffix" match 2; 
dn.one="ou=people,o=suffix" match 3, and 5; 
dn.subtree="ou=people,o=suffix" match 2, 3, 4, and 5; and 
dn.children="ou=people,o=suffix" match 3, 4, and 5.

 

posted on 2017-05-05 10:49  西风古道  阅读(355)  评论(0编辑  收藏  举报