一、用setup安装最简单 

yum install nss-pam-ldapd

 
[root@sgnbj-192-168-1-99 ~]# cat /etc/passwd|grep test
[root@sgnbj-192-168-1-99 ~]# id test              
uid=10000(test) gid=10001 groups=10001  ##成功了
 
 
或如下修改客户端
1、 
yum install openldap-clients
yum install nss-pam-ldapd
 
开启nslcd服务
 vim /etc/nslcd.conf
 
uid nslcd
gid ldap
# This comment prevents repeated auto-migration of settings.
uri   ldap://192.168.10.70/
base  dc=example,dc=com
ssl no
 
/etc/init.d/nslcd start
 
2、  AUTH
 用来跟踪特定身份验证机制是否已经启用的文件是 /etc/sysconfig/authconfig  我们可以希望以下条目的值都是 “yes”:
USELDAP=yes
USELDAPAUTH=yes
PASSWDALGORITHM=md5
USESHADOW=yes
USELOCAUTHORIZE=yes
 
3、
PAM 和 NSS 模块使用的基本配置文件是 /etc/openldap/ldap.conf。host 选项指定 LDAP 服务器,base 选项指定这个目录使用的 DN,最初
 
我们希望关闭加密功能:
 
URI ldap://192.168.10.70/
BASE dc=example,dc=com
TLS_CACERTDIR /etc/openldap/certs
 
4.  NSS
要让 NSS 服务使用 OpenLDAP 服务器,需要将 “ldap” 添加到 /etc/nsswitch.conf 文件的 passwd、shadow 和 group 行中,如下所示:
 passwd: files ldap
shadow: files ldap
group: files ldap
 
5.  PAM
/etc/pam.d/system-auth 添加
 auth        sufficient    pam_ldap.so use_first_pass
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so
password    sufficient    pam_ldap.so use_authtok
session     optional      pam_ldap.so
 
 
 
二、限制非linux帐号登录
vim /etc/pam_ldap.conf  
pam_min_uid 500        
pam_max_uid 6000
##设置认证登录的uid范围,防止非法登录 如:若account的uid=0的话 就有root权限, 提高安全性 (可以在ldap上设置linux帐号为这段uid)
 
e.g:
[root@175 ~]# id test
uid=10000(test) gid=10001 groups=10001
 
[root@www ~]# ssh test@192.168.10.175
test@192.168.10.175's password:
UID must be less than 6000
Connection closed by 192.168.10.175
 
 
 
三、 设置登录用户的家目录
 
默认设置登录一个linux系统没有的帐号,不会创建该帐号的家目录
[root@www ~]# ssh test@192.168.10.175
test@192.168.10.175's password:
Last login: Mon Nov 12 17:43:06 2012 from 192.168.10.70
Could not chdir to home directory /home/test: No such file or directory
-bash-4.1$ pwd
/
 
修改配置:
vim /etc/pam.d/sshd   添加
session required        pam_mkhomedir.so skel=/etc/skel/ umask=0077
 
测试:
e.g:
[root@sgnbj-192-168-1-99 home]# ls
svn
 
[root@www ~]# ssh test@192.168.10.175
test@192.168.10.175's password:
Creating directory '/home/test'.
Last login: Mon Nov 12 18:47:52 2012 from 192.168.10.70
[test@sgnbj-192-168-1-99 ~]$ pwd
/home/test
[test@sgnbj-192-168-1-99 ~]$ ls /home/
svn  test