2009年8月30日 星期日

如何設定 ldap 登入服務 – OpenLDAP Linux authentication howto

OpenLDAP 登入服務器

上文提到如何安裝 OpenLDAP 服務器, 今次將會提到如何在 ubuntu上把 OpenLDAP 服務器設定成一個登入服務器. 這樣你就可以使用同一組資料登入多個不同的服務器.

先作服務器端設定

安裝轉換工具 migration tools
sudo apt-get install migrationtools
更改 migration_common.ph 設定檔, 位置在 /usr/share/perl5
sudo vi /usr/share/perl5/migration_common.ph
根據服務器端的設計更改以下兩行
# Default DNS domain
$DEFAULT_MAIL_DOMAIN = “example.com”;
# Default base
$DEFAULT_BASE = “dc=example,dc=com”;
開始轉移登入資料 (/tmp 改成你的理想位置)
export ETC_SHADOW=/etc/shadow #把shadow 跟passwd 一同載入
./migrate_base.pl > /tmp/base.ldif
./migrate_group.pl /etc/group /tmp/group.ldif
./migrate_hosts.pl /etc/hosts /tmp/hosts.ldif
./migrate_passwd.pl /etc/passwd /tmp/passwd.ldif
用以下命令分別載入到 ldap 服務器
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/base.ldif
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/group.ldif
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/passwd.ldif
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/hosts.ldif
apt-get install 安裝認證需要的元件
Modules require for authentication
libnss-ldap – NSS module for using LDAP as a naming service
libpam-ldap – Pluggable Authentication Module allowing LDAP interfaces
libnss-ldapd – NSS module for using LDAP as a naming service
perdition-ldap – Library to allow perdition to access LDAP based popmaps
libpam-cracklib
pam library做小許 bug fix
ln -s pam_unix.so pam_pwdb.so
這樣, 服務器端的設定就完成了

再做客戶端的設定

Vi /etc/ldap.conf
host ldap.example.com
uri ldap://<服務器ip位置>:389/
base ou=People,dc=example,dc=com
nss_initgroups_ignoreusers backup,bin,daemon,dhcp,games,gnats,irc,klog,libuuid,list,lp,mail,man,munin,mysql,news,openldap,proxy,root,sshd,sync,sys,syslog,uucp,www-data
vi /etc/nsswitch.conf # 登入方法設定
passwd: ldap compat
shadow: ldap compat
group: ldap compat
vi /etc/pam.d/common-account #設定 account 認證方法
account sufficient pam_ldap.so
account required pam_unix.so try_first_pass
vi /etc/pam.d/common-auth # 設定登入認證方法
auth sufficient pam_ldap.so
auth requisite pam_unix.so nullok_secure try_first_pass
auth optional pam_smbpass.so migrate missingok
vi /etc/pam.d/common-password #設定密碼管理
password sufficient pam_ldap.so
password required pam_unix.so nullok obscure min=4 max=8 md5 try_first_pass
password optional pam_smbpass.so nullok use_authtok use_first_pass missingok

測試設定

getent passwd | grep
會發現參數出現兩次
這樣客戶端就能使用中央使用者管理

沒有留言:

張貼留言