基本概念
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/(仅服务端)
OpenSSH:
http://www.openssh.org/
需要修改的文件
服务器端:
/etc/openldap/slapd.conf
客户端:
/etc/ldap.conf
/etc/pam.d/system-auth
/etc/sysconfig/authconfig
/etc/nsswitch.conf
/etc/hosts
/etc/ssh/sshd_config
要重启的服务
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
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/(仅服务端)
- # cd openldap- 2.3 .XX
- # ./configure --prefix = /usr --sysconfdir = /etc --libexecdir = /usr/sbin --mandir = /usr/share/man --enable-bdb --enable-crypt --with-tls --without-cyrus-sasl --enable-ldbm
- # make depend
- # make clean
- # make
- # make install
- # cd /var/tmp
- # tar xvf openssh- 3 .X.XpX.tar
- # cd openssh- 3 .X.XpX
- # ./configure --prefix = /usr --with-pam --sysconfdir = /etc/ssh --with-ssl-dir = /usr
服务器端:
/etc/openldap/slapd.conf
- include /etc/openldap/schema/core.schema
- include /etc/openldap/schema/cosine.schema
- include /etc/openldap/schema/inetorgperson.schema
- include /etc/openldap/schema/nis.schema
- loglevel - 1
- access to attrs = shadowLastChange , userPassword
- by self write
- by * auth
- access to *
- by * read
- TLSCipherSuite HIGH:MEDIUM:+SSLv2
- TLSCACertificateFile /etc/openldap/cacert.pem
- TLSCertificateFile /etc/openldap/slapd-cert-ldap1.pem
- TLSCertificateKeyFile /etc/openldap/slapd-key-ldap1.pem
- TLSVerifyClient never
- database bdb
- suffix " dc=example,dc=com "
- rootdn " cn=Manager,dc=example,dc=com "
- rootpw secret
- directory /var/lib/ldap
- index objectClass eq
/etc/ldap.conf
- host ldap1.example.com
- base dc = example , dc = com
- ssl start_tls
- tls_cacertfile /tmp/cacert.pem
/etc/pam.d/system-auth
- auth required /lib/security/$ISA/pam_env.so
- auth sufficient /lib/security/$ISA/pam_unix.so likeauth nullok
- auth sufficient /lib/security/$ISA/pam_ldap.so use_first_pass
- auth required /lib/security/$ISA/pam_deny.so
- account sufficient /lib/security/$ISA/pam_ldap.so
- account required /lib/security/$ISA/pam_unix.so broken_shadow
- password required /lib/security/$ISA/pam_cracklib.so retry = 3 type =
- password sufficient /lib/security/$ISA/pam_unix.so nullok use_authtok md5 shadow
- password required /lib/security/$ISA/pam_deny.so
- session required /lib/security/$ISA/pam_limits.so
- session required /lib/security/$ISA/pam_unix.so
- USEDB = no
- USEHESIOD = no
- USELDAP = yes
- USENIS = no
- USEKERBEROS = no
- USELDAPAUTH = yes
- USEMD5 = yes
- USESHADOW = yes
- USESMBAUTH = no
- passwd: files ldap
- shadow: files
- group: files ldap
- hosts: files dns
- bootparams: nisplus [ NOTFOUND=return ] files
- ethers: files
- netmasks: files
- networks: files
- protocols: files ldap
- rpc: files
- services: files ldap
- netgroup: files ldap
- publickey: nisplus
- automount: files ldap
- aliases: files nisplus
- 127.0.0.1 MD_Mother_HDA localhost
- 10.56.28.33 ldap1.example.com
- PasswordAuthentication yes
- ChallengeResponseAuthentication yes
- UsePAM yes
- 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