linux下openldap配置问题

本文发布时间: 2019-Mar-22
公司需要新配置ldap服务器,在配置时遇到了以下问题,当服务端用centos6.0及以上版本,客户端用centos5.4版本,假如其中一个客户端的ip地址是172.16.16.31,当用server端设定用户登陆172.16.16.31时,通过在server端配置,能够自动为用户创建家目录;但是如果客户端的机器是用centos6.0及以上版本的话,就不能为登录用户自动创建家目录,不知道这个是为什么?还有就是用户的密码如果采用MD5或SHA1加密的话,用户不能登录进去,只能采用crypt加密方式,如下为具体的配置:一、ldap服务端配置:#yum -y install openldap openldap-clients openldap-servers db4-* perl-* 然后在/etc/openldap下应该有一个slapd.conf。如果该目录下没有这个文件,则用find查找,找到这个文件然后拷贝到/etc/openldap目录下,打开这个文件,然后修改suffix为你的公司或域名的DNS表示,如我测试用example.com,那么这里便可以写成"dc=example,dc=com"。rootdn则是openLDAP中最高权限用户,在这里我们把它写成"cn=root,dc=example,dc=com"。当然你也可以取其它的名字如"cn=Manager,dc=example,dc=com",但是cn=username后面那一串一定要和你的suffix一致。接下来要设置rootdn的密码,如果你不希望密码使用明文保存的话,最好是用slappasswd来生成一个。直接运行slappasswd命令,然后两次键入想要生成的密码,一个加密后的字符串便显示了出来。使用任何办法复制这个字符串,并重新打开slapd.conf,在rootdn下一行添加rootpw 刚才的字符串保存退出即完成了密码的配置。在启动openLDAP服务器之前,把DB_CONFIG.example拷贝为/var/lib/ldap/DB_CONFIG,这个文件你可以用find命令来查找,而在我这里则是#cp /usr/share/doc/openldap-servers-2.4.19/DB_CONFIG.example /var/lib/ldap/DB_CONFIG#chown -R ldap:ldap /var/lib/ldap/#chmod 700 /var/lib/ldap然后,还要把/etc/openldap/slapd.d这个文件夹删除或者改名,否则slapd会无视你的slapd.conf配置文件的!好了,可以启动LDAP服务器了,运行"service slapd start"。启动起来后,就可以添加记录文件openldap.ldif(特别要注意格式,每段红色部分在冒号之后有个空格,)dn: dc=example,dc=com //表示建立初始化记录文件,也相当于根域dc: exampleobjectClass: topobjectClass: domaindn: ou=People,dc=example,dc=com //表示建立用户ou: PeopleobjectClass: topobjectClass: organizationalUnitdn: ou=Group,dc=example,dc=com //建立群组ou: GroupobjectClass: topobjectClass: organizationalUnitdn: cn=IT,ou=Group,dc=example,dc=com //表示在Group群下建立IT这个成员组gidNumber: 61userPassword:: e2NyeXB0fXg=objectClass: posixGroupobjectClass: topcn: ITdn: cn=CC,ou=Group,dc=example,dc=com // 表示在Group群下建立CC这个成员组gidNumber: 62userPassword:: e2NyeXB0fXg=objectClass: posixGroupobjectClass: topcn: CCdn: uid=luck.yang,ou=People,dc=example,dc=com //表示建立的luck.yang这个用户属于People这个组且属于IT成员组uid: luck.yangcn: luck.yangobjectClass: accountobjectClass: posixAccountobjectClass: topuserpassword: {crypt}izU9XMB+E1d2CHEfRgL8tw== loginShell: /bin/bashuidNumber: 600gidNumber: 61homeDirectory: /home/luck.yangdn: uid=hugo.yao,ou=People,dc=example,dc=com //表示建立的hugo.yao这个用户属于People这个组且属于IT成员组uid: hugo.yaocn: hugo.yaoobjectClass: accountobjectClass: posixAccountobjectClass: topuserpassword: {crypt}izU9XMB+E1d2CHEfRgL8tw== loginShell: /bin/bashuidNumber: 601gidNumber: 61homeDirectory: /home/hugo.yao保存后导入ldap,使用ldapadd命令#cd /etc/openldap/# ldapadd -x -D "cn=root,dc=example,dc=com" -W -f ./openldap.ldif,执行后,会让你输入密码,这个密码就是在slapd.conf中那个密码,导入。可以通过以下这个命令来查看导入情况 #ldapsearch -x -b 'dc=example,dc=com' 要增加用户到People下且属于CC或IT或其他成员组,按照上面的配置文件来添加就可以,只是要注意格式,添加后导入ldap即可,已经添加了的不能再添加。这样ldap服务端就配置好了。 二、客户端配置(以centos 5.4为例 )服务端配置好后,接下来配置客户端,也就是客户想要访问的主机。把用户配置在ldap服务器上,在客户机上做好相应的配置后,当用户需要去访问某台客户机时,在该客户机上输入密码后,会到ldap服务器来做验证。LDAP服务器的客户端命令RPM包为openldap-clients,或用yum -y install openldap-clients安装,安装后会有 /etc/openldap/ldap.conf文件。 除此之外要实现LDAP服务客户端必须配置 /etc/nsswitch.conf, /etc/sysconfig/authing, /etc/openldap/ldap.conf, /etc/ldap.conf /etc/pam.d/system-auth五个文件,其中/etc/ldap.conf这个配置文件是nss_ldap这个软件生成的,另外需要的nss_ldap和nscd两个软件在系统安装时就会自动安装。接下来配置这些文件:<1>配置/etc/nsswith.conf /etc/nsswith.conf文件由glibc-2.5-24生成,CentOS5.2中缺省安装。该文件用 于名称转换服务。通常LINUX系统身份验证读取本地文件,要使身份验证查询 通过LDAP服务器必须在该文件中找到passwd;shadow;group;三行在files后空格添加“ldap” passwd: files ldap shadow: files ldap group: files ldap <2>配置/etc/sysconfig/authconfig文件提供身份验证支持LDAP功能 /etc/sysconfig/authconfig 文件由authconfig-5.3.21-3.e15RPM包生成系统默认安装。配置该文件用来跟踪LDAP身份认证机制是否正确启用。找到以下七行,将值确定为“yes”。 USESYSNETAUTH=yes USESHADOW=yes USELOCAUTHORIZE=yes USELDAP=yes USELDAPAUTH=yes USEMKHOMEDIR=yes PASSWDALGORITHM=yes <3>配置/etc/pam.d/system-auth文件 身份验证服务是实际向LDAP验证用户身份的服务。可插入身份验证模块(PAM)提供了本地Linux身份验证服务。pam_unix.so模块是通用模块,使PAM机制对本地的/etc/passwd文件检查用户帐号。PAMLDAP模块可以用来将身份验证重定向到LDAP目录上。身份验证本身是由PAM程序执行的,它从身份验证候选机制中获取用户名,将其绑定到openLDAP 服务器上。如果绑定成功,PAM会报告说这个用户已经成功通过了pam_ldap.so提供的身份验证测试。根据PAM的配置不同,在用户看到命令提示符之前可能会执行其它测试。/etc/pam.d/system-auth文件是CentOS5.2的系统认证PAM文件。在该文件的auth,account,password,session四段中pam_unix.so模块后添加pam_ldap.so模块使身份验证先对本地的/etc/passwd文件检查用户帐号,然后再对LDAP服务器进行检查。同时因为是LDAP认证需要为用户创建根目录,所以还必须在会话(SESSION)阶段增加pam_mkhomedir.so模块,为用户登录自动创建宿主目录。 #cp /etc/pam.d/system-auth /etc/pam.d/system-auth.old *首先备份系统认证文件,同时PAM配置文件至关重要,稍有差池,用户可能就不能登录,所以需开两个控制台调试以防万一。 我的配置如下: #%PAM-1.0# This file is auto-generated.# User changes will be destroyed the next time authconfig is run.auth required pam_env.soauth sufficient pam_unix.so nullok try_first_passauth requisite pam_succeed_if.so uid >= 500 quietauth sufficient pam_ldap.soauth required pam_deny.soaccount required pam_unix.so broken_shadowaccount sufficient pam_succeed_if.so uid < 500 quietaccount sufficient pam_ldap.soaccount required pam_permit.sopassword requisite pam_cracklib.so try_first_pass retry=3password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtokpassword sufficient pam_ldap.so use_authtok md5password required pam_deny.sosession optional pam_keyinit.so revokesession required pam_limits.sosession [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uidsession required pam_unix.sosession required pam_mkhomedir.so skel=/etc/skel/ umask=0022session optional pam_ldap.so<4>/etc/openldap/ldap.conf.(该文件可不配置) 该文件是LDAP服务器的客户端搜索工具文件,由openldap_clientsRPM包生成。 配置如下: BASE dc=boy,dc=com ->搜索路径 URI ldap://主服务器名(主), ldap://辅助服务器名 (备) 我的配置如下: BASE dc=example,dc=com URI ldap://172.16.16.222:389/ <5>/etc/ldap.conf 文件。 该文件也是LDAP服务器客户端文件,但是与/etc/openldap/ldap.conf文件有不同功能,两者不可混淆。该文件由nss_ldap-253-12.e15RPM包生成,系统默认安装。/lib/security/pam_ldap.so也是由该RPM包生成。 Rpm包nss_ldap-253说明 nss_ldap-253: 包括两个LDAP访问客户机:nss_ldap和pam_ldap。nss_ldap是一组C库扩展,提供系统命名服务(NSS),也叫名称转换服务。需要配置为使用LDAP来解析诸如用户和组帐号资源。 #vi /etc/ldap.conf 按shift+g跳到最后,加上下面几句: uri ldap://:389/ssl offtls_cacertdir /etc/openldap/cacertspam_password crypt<6>开启名称缓存服务nscd. 通过网络方式查询用户占用带宽且有时延,开启名称缓存服务可以节省网络资源提高查询效率。 service nscd restart chkconfig --level 3 5 nscd on 现在可以在客户端进行登录认证调试。 在客户端使用getent passwd, getent group 命令会显示所有的用户和组包括本地/etc/passwd/下的和LDAP服务器端数据库上的。 至此在centos5.4版本测试上成功。三、客户端配置:以centos 6.0版本为例#yum -y install openldap-clients nss-pam-ldapd #vi /etc/openldap/ldap.conf # add at the last line# LDAP server's URI#URI ldap:/// # specify Suffix#BASE dc=server,dc=world#TLS_CACERTDIR /etc/openldap/cacertsBASE dc=idc,dc=timanetwork,dc=com URI ldap://:389 ssl no tls_cacertdir /etc/openldap/cacerts pam_password crypt #vi /etc/nslcd.conf 跳到最后加上如下内容# line 131: specify URI, Suffixuri ldap://:389/base dc=idc,dc=timanetwork,dc=comssl notls_cacertdir /etc/openldap/cacerts#vi /etc/pam_ldap.conf 跳到最后加上如下内容# line 17: make it comment#host 127.0.0.1# line 20: specify Suffixbase dc=server,dc=world# add at the last lineuri ldap://:389/ssl notls_cacertdir /etc/openldap/cacertspam_password crypt#vi /etc/pam.d/system-auth# add like follows#%PAM-1.0# This file is auto-generated.# User changes will be destroyed the next time authconfig is run.auth required pam_env.soauth sufficient pam_fprintd.soauth sufficient pam_unix.so nullok try_first_passauth requisite pam_succeed_if.so uid >= 500 quietauth sufficient pam_ldap.so use_first_passauth required pam_deny.soaccount required pam_unix.soaccount sufficient pam_localuser.soaccount sufficient pam_succeed_if.so uid < 500 quietaccount [default=bad success=ok user_unknown=ignore] pam_ldap.soaccount required pam_permit.sopassword requisite pam_cracklib.so try_first_pass retry=3 type=password sufficient pam_unix.so sha512 md5 shadow nullok try_first_pass use_authtokpassword sufficient pam_ldap.so use_authtokpassword required pam_deny.sosession optional pam_keyinit.so revokesession required pam_limits.sosession [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uidsession required pam_unix.sosession optional pam_ldap.sosession optional pam_mkhomedir.so skel=/etc/skel umask=077#vi /etc/nsswitch.confpasswd: files ldapshadow: files ldapgroup: files ldapnetgroup: ldapautomount:files ldap #vi /etc/sysconfig/authconfiguseldap=yes#service nslcd start#chkconfig nslcd on#shutdown -r now#service nscd stop //这个服务需要停掉,不然不能访问至此在centos6.0上客户端配置好了,但是当用户去访问这台机器时,能够登录进去,但是不能自动创建家目录。由于公司现在很多机器都是安装的centos6.0或redhat6.0版本,不能自动创建家目录,所以我只有用nfs文件共享/home目录,具体方法如下:在ldap服务端配置nfs服务器,步骤如下:#yum -y install nfs-utils#vi /etc/idmapd.conf 加入/home *(rw,sync,no_root_squash,no_all_squash) 保存。解释一下意思/home 共享的目录* 表示允许所有来共享rw 表示可写no_root_squash 表示有root特权no_all_squash 表示能够用户认证#/etc/init.d/rpcbind start#/etc/init.d/nfslock start#/etc/init.d/nfs start#chkconfig rpcbind on#chkconfig nfslock on#chkconfig nfs on这样就可以在/home目录下手动建立要登陆的用户的家目录。客户端配置nfs#yum -y install nfs-utils# /etc/init.d/rpcbind start#/etc/init.d/nfslock start#/etc/init.d/netfs start#chkconfig rpcbind on#chkconfig nfslock on#chkconfig netfs on在/etc/fstab中增加一行::/home /home nfs defaults 1 1#mount -t nfs :/home /home这样当用户登录进去后,就可以共享server端手动建立的家目录,但是如果用户过多的话,不是很方便,不知道有没有哪位朋友遇到过这种情况,如果有的话,请给些建议,谢谢!本文出自 “ˇ非ˉ遗忘” 博客http://yangchangwu.blog.51cto.com/2521077/904202


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:11pm
栏目列表