Xenで仮想サーバをたくさん立ち上げる予定なので、それぞれにユーザ管理などをしていられない。LDAPを使って統合認証をする。
【サーバ側の設定】
①LDAPサーバのインストール
Use LDAPとUse LDAP AuthenticationをチェックしNext
Serverにldap://127.0.0.1、Base DNにdc=grandarbre,dc=netを書いてOK
⑧初期エントリを作成
⑪ユーザ、グループの登録
LDAPでユーザー認証をするクライアント側の設定は簡単だ。
①LDAPクライアントのインストール
上手くいかなかったらLDAPサーバに接続できているかどうかを確認。
【サーバ側の設定】
①LDAPサーバのインストール
[root@ns1 ~]#yum install openldap-servers [root@ns1 ~]#yum install openldap-clients②パスワードの暗号化準備
[root@ns1 ~]# slappasswd -h {MD5} -s test
{MD5}CY9rzUYh03PK3k6DJie09g==
③LDAPサーバの設定[root@ns1 ~]#vi /etc/openldap/slapd.conf
access to attrs=userPassword
by self write
by dn="cn=Manager,dc=grandarbre,dc=net" write
by anonymous auth
by * none
access to *
by self write
by dn="cn=Manager,dc=grandarbre,dc=net" write
by * read
database bdb
suffix "dc=grandarbre,dc=net"
rootdn "cn=Manager,dc=grandarbre,dc=net"
rootpw {MD5}CY9rzUYh03PK3k6DJie09g==
⑤DBの設定ファイルをコピー[root@ns1 ~]#cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG⑥LDAPサーバの起動
[root@ns1 ~]# chkconfig ldap on [root@ns1 ~]# service ldap start⑦authconfig-tuiでLDAP認証の設定
Use LDAPとUse LDAP AuthenticationをチェックしNext
Serverにldap://127.0.0.1、Base DNにdc=grandarbre,dc=netを書いてOK
⑧初期エントリを作成
[root@ns1 ~]# cat first.ldif dn: dc=grandarbre,dc=net objectclass: dcObject objectclass: organization o: Grand Arbre Net dc: grandarbre dn: cn=Manager,dc=grandarbre,dc=net objectclass: organizationalRole cn: Manager
[root@ns1 ~]# cat people.ldif dn: ou=People,dc=grandarbre,dc=net ou: People objectClass: top objectClass: organizationalUnit
[root@ns1 ~]# cat group.ldif dn: ou=Group,dc=grandarbre,dc=net objectClass: organizationalUnit ou: Group⑨初期エントリの登録
[root@ns1 ~]# ldapadd -x -D "cn=Manager,dc=grandarbre,dc=net" -W -f first.ldif Enter LDAP Password: adding new entry "dc=grandarbre,dc=net" adding new entry "cn=Manager,dc=grandarbre,dc=net" [root@ns1 ~]# ldapadd -x -D "cn=Manager,dc=grandarbre,dc=net" -W -f people.ldif Enter LDAP Password: adding new entry "ou=People,dc=grandarbre,dc=net" [root@ns1 ~]# ldapadd -x -D "cn=Manager,dc=grandarbre,dc=net" -W -f group.ldif Enter LDAP Password: adding new entry "ou=Group,dc=grandarbre,dc=net"⑩ユーザエントリ、グループエントリのLDIFを作る
[root@ns1 ~]# cat user-entry.ldif
dn: uid=user1,ou=People,dc=grandarbre,dc=net
uid: user1
cn: user1
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$gOT2iaVH$kd2TfJBVS7r/F1bYQryTa0
shadowLastChange: 13813
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 500
gidNumber: 500
homeDirectory: /home/user1
[root@ns1 ~]# cat group-entry.ldif
dn: cn=ishii,ou=Group,dc=grandarbre,dc=net
objectClass: posixGroup
objectClass: top
cn: user1
userPassword: {crypt}x
gidNumber: 500
既に/etc/passwdに登録しているユーザ、グループを移行する場合は[ishii@ns1 ~]$ /usr/share/openldap/migration/migrate_passwd.pl /etc/passwd > user-entry.ldif [ishii@ns1 ~]$ /usr/share/openldap/migration/migrate_group.pl /etc/group > group-entry.ldifで自動的に生成されるので、必要なユーザエントリだけを切り出して使う。ただし一行目のdc=○○がdn: uid=user1,ou=People,dc=padl,dc=comなどとなってしまうので、これは手で直す。(ちゃんと設定すればいいんだと思うが...)
⑪ユーザ、グループの登録
[root@ns1 ~]# ldapadd -x -D "cn=Manager,dc=grandarbre,dc=net" -W -f user-entry.ldif [root@ns1 ~]ldapadd -x -D "cn=Manager,dc=grandarbre,dc=net" -W -f group-entry.ldif⑫ここまで登録できたら検索をしてみる
[root@ns1 ~]#ldapsearch -H ldap://localhost -x -b"dc=grandarbre,dc=net" "(objectclass=*)" # extended LDIF # # LDAPv3 # base⑬他のサーバからこのユーザ(/etc/passwdには書いていない)でログインをしてみる。with scope subtree # filter: (objectclass=*) # requesting: ALL # # grandarbre.net dn: dc=grandarbre,dc=net objectClass: dcObject objectClass: organization o: Grand Arbre Net dc: grandarbre # Manager, grandarbre.net dn: cn=Manager,dc=grandarbre,dc=net objectClass: organizationalRole cn: Manager # People, grandarbre.net dn: ou=People,dc=grandarbre,dc=net ou: People objectClass: top objectClass: organizationalUnit # user1, People, grandarbre.net dn: uid=user1,ou=People,dc=grandarbre,dc=net uid: user1 cn: user1 objectClass: account objectClass: posixAccount objectClass: top objectClass: shadowAccount shadowLastChange: 13813 shadowMax: 99999 shadowWarning: 7 loginShell: /bin/bash uidNumber: 500 gidNumber: 500 homeDirectory: /home/user1 # search result search: 2 result: 0 Success # numResponses: 5 # numEntries: 4
[ishii@www ~]$ ssh -l user1 ns1 user1@ns1's password: Last login: Sun Oct 28 06:28:03 2007 from www [user1@ns1 ~]$⑭iptablesを修正して他のサーバからLDAP接続を許可する。
[root@ns1 ~]# vi /etc/sysconfig/iptables ... -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT ... [root@ns1 ~]# service iptables restart【クライアント側の設定】
LDAPでユーザー認証をするクライアント側の設定は簡単だ。
①LDAPクライアントのインストール
[root@www ~]# yum install openldap-clients②LDAP認証の設定
[root@www ~]# authconfig-tuiこれで他のサーバからログインをしてみる。
上手くいかなかったらLDAPサーバに接続できているかどうかを確認。
[root@www ~]# ldapsearch -H ldap://ns1/ -x -b"dc=grandarbre,dc=net" "(objectclass=*)"ns1の名前解決ができていない場合は/etc/hostsに書くか、IP指定にすればよい。