LDAP+OpenSSL集中认证配置

基本概念
LDAP是以树方式组织的数据库。每个节点可以有什么值是通过类来定义。
LINUX或者其它应用的认证就是来BIND LDAP树上的节点,如果能够BIND,就算认证成功。
要改变LINUX认证方式,需要让名字服务NSCD能够到LDAP查找用户,这需要nss_ldap.so。
得到用户后,再到LDAP去认证,这需要pam_ldap.so实现。

公私钥:公钥可以唯一解密私钥加密过的数据,反之亦然。
SSL过程:需要两对公私钥(P1,V1),(P2,V2),假设通信双方是A和B,B是服务器,A要确认和它通信的是B:
A->B: hello
B->A: 用V2加密过的P1(即用户证书,A就用P2解密出P1)
A->B: ok
B->A: 用V1加密的一段信息
A->B: 用P1加密一个自动生成的K(用之前的P1解密成功这段信息则认为B是可信的了)
B->A: 用K加密的数据(之后两对密钥功能结束,由K来加解密数据)
这里,P2就是第3方的CA证书,由于非对称加密很慢,所以公私钥只是用来保证K的传送安全,之后通信是用K的对称加密算法来保证。


需要安装的组件
Berkeley DB 4.2.52 or later - http://www.sleepycat.com/(仅服务端)
NSS_LDAP 2.2.X or PAM_LDAP 1.6.X or later – http://www.padl.com/(仅客户端)
OpenSSL 0.9.7e or later – http://www.openssl.org/

OpenLDAP 2.3.XX or later - http://www.openldap.org/(仅服务端)

  1.  # cd openldap- 2.3 .XX
  2. # ./configure --prefix = /usr --sysconfdir = /etc --libexecdir = /usr/sbin --mandir = /usr/share/man --enable-bdb --enable-crypt --with-tls --without-cyrus-sasl --enable-ldbm
  3. # make depend
  4. # make clean
  5. # make
  6. # make install
  7.  
OpenSSH: http://www.openssh.org/
  1. # cd /var/tmp
  2. # tar xvf openssh- 3 .X.XpX.tar
  3. # cd openssh- 3 .X.XpX
  4. # ./configure --prefix = /usr --with-pam --sysconfdir = /etc/ssh --with-ssl-dir = /usr 
需要修改的文件
服务器端:
/etc/openldap/slapd.conf
  1. include   /etc/openldap/schema/core.schema
  2. include   /etc/openldap/schema/cosine.schema
  3. include   /etc/openldap/schema/inetorgperson.schema
  4. include   /etc/openldap/schema/nis.schema
  5. loglevel - 1 
  6.  
  7. access to attrs = shadowLastChange , userPassword
  8.       by self write
  9.       by * auth
  10. access to *
  11.       by * read
  12. TLSCipherSuite  HIGH:MEDIUM:+SSLv2
  13. TLSCACertificateFile /etc/openldap/cacert.pem
  14. TLSCertificateFile /etc/openldap/slapd-cert-ldap1.pem
  15. TLSCertificateKeyFile /etc/openldap/slapd-key-ldap1.pem
  16. TLSVerifyClient never 
  17. database    bdb
  18. suffix         " dc=example,dc=com " 
  19. rootdn         " cn=Manager,dc=example,dc=com " 
  20. rootpw        secret
  21. directory               /var/lib/ldap
  22. index    objectClass    eq 
客户端:
/etc/ldap.conf
  1.  host ldap1.example.com
  2. base dc = example , dc = com
  3. ssl start_tls
  4. tls_cacertfile /tmp/cacert.pem 

  /etc/pam.d/system-auth

  1.  auth        required      /lib/security/$ISA/pam_env.so
  2. auth        sufficient    /lib/security/$ISA/pam_unix.so likeauth nullok
  3. auth        sufficient    /lib/security/$ISA/pam_ldap.so use_first_pass
  4. auth        required      /lib/security/$ISA/pam_deny.so
  5. account     sufficient /lib/security/$ISA/pam_ldap.so
  6. account     required      /lib/security/$ISA/pam_unix.so broken_shadow
  7. password    required      /lib/security/$ISA/pam_cracklib.so retry = 3  type = 
  8. password    sufficient    /lib/security/$ISA/pam_unix.so nullok use_authtok md5 shadow
  9. password    required      /lib/security/$ISA/pam_deny.so
  10. session     required      /lib/security/$ISA/pam_limits.so
  11. session     required      /lib/security/$ISA/pam_unix.so
  12.  
/etc/sysconfig/authconfig
  1. USEDB = no
  2. USEHESIOD = no
  3. USELDAP = yes
  4. USENIS = no
  5. USEKERBEROS = no
  6. USELDAPAUTH = yes
  7. USEMD5 = yes
  8. USESHADOW = yes
  9. USESMBAUTH = no 
/etc/nsswitch.conf
  1. passwd:     files ldap
  2. shadow:     files
  3. group:      files ldap
  4. hosts:      files dns
  5. bootparams: nisplus  [ NOTFOUND=return ]  files
  6. ethers:     files
  7. netmasks:   files
  8. networks:   files
  9. protocols:  files ldap
  10. rpc:        files
  11. services:   files ldap
  12. netgroup:   files ldap
  13. publickey:  nisplus
  14. automount:  files ldap
  15. aliases:    files nisplus 
/etc/hosts
  1.  127.0.0.1        MD_Mother_HDA localhost
  2.  10.56.28.33      ldap1.example.com 
/etc/ssh/sshd_config
  1. PasswordAuthentication yes
  2. ChallengeResponseAuthentication yes
  3. UsePAM yes
  4. Subsystem       sftp    /usr/libexec/sftp-server 
要重启的服务
service nscd restart       
service sshd restart

另外,这个文件是LDAP命令使用的,不是系统认证所需:
/etc/openldap/ldap.conf

开始的时候可以不要SSL认证,只需要注释掉ldap.conf中start_tls一句即可。另外,SSL要求验证服务器,所以一定要在/etc/hosts文件里加入服务器完整名字,并与SSL证书中一致。

原文:http://www.blogjava.net/alwayscy/archive/2006/11/28/83737.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值