Linuxのログイン認証をOpenLDAPにする
CentOS4.5 + OpenLDAP2.2.13 での設定メモ。
- インストール
# yum -y install openldap-clients openldap-servers
- slapdの設定
/etc/openldap/slapd.conf を編集する。
#suffix "dc=my-domain,dc=com" suffix "dc=rukatan,dc=com" #rootdn "cn=Manager,dc=my-domain,dc=com" rootdn "cn=root,dc=rukatan,dc=com"
rootpw の値は、以下の方法で作成する。
# slappasswd -h {MD5} New password: Re-enter new password: {MD5} ***************************
この値を /etc/openldap/slapd.conf のrootpwに設定する。
rootpw {MD5}*****************************
パスワードのアクセス権を設定する。
access to attrs=userPassword <- パスワードのアクセス by self write <- 自分自身は変更可 by dn="cn=root,dc=rukatan,dc=com" write <- rootは書き込み可 by anonymous auth <- 認証が必要 by * none <- アクセス不可 access to * <- その他のattrのアクセス by dn="cn=root,dc=rukatan,dc=com" write <- rootは書き込み可 by self write <- 自分自身は変更可 by * read <- 読み込みは可
- 基本データベースの作成
base.ldif という名前で以下のとおりファイルを作成する。
dn: dc=rukatan,dc=com objectClass: dcObject objectClass: organization o: developper dc: rukatan dn: cn=root,dc=rukatan,dc=com objectClass: organizationalRole cn: root dn: ou=People,dc=rukatan,dc=com objectClass: organizationalUnit ou: People dn: ou=Group,dc=rukatan,dc=com objectClass: organizationalUnit ou: Group
# ldapadd -h localhost -x -D "cn=root,dc=rukatan,dc=com" -W -f base.ldif
- ユーザの追加
inahou というユーザを追加します。
user.ldif を下記のように作成します。
dn: uid=inahou,ou=People,dc=rukatan,dc=com uid: inahou cn: inahou objectClass: account objectClass: posixAccount objectClass: top objectClass: shadowAccount userPassword: {CRYPT}***************** shadowLastChange: 1 shadowMax: 99999 shadowWarning: 7 loginShell: /bin/bash uidNumber: 500 gidNumber: 500 homeDirectory: /home/inahou
userPassword の値は、
slappasswd -h {crypt}
の出力結果を使います。
以下のコマンドで追加できます。
# ldapadd -h localhost -x -D "cn=root,dc=rukatan,dc=com" -W -f user.ldif
同様にグループも追加します。group.ldif のような適当な名前で下記のようなファイルを作成します。
dn: cn=inahou,ou=Group,dc=rukatan,dc=com objectClass: posixGroup objectClass: top cn: inahou gidNumber: 500
以下のコマンドで追加できます。
# ldapadd -h localhost -x -D "cn=root,dc=rukatan,dc=com" -W -f group.ldif
authconfig または、system-config-authentication を実行します。コマンドが無い場合には、以下のように追加します。
# yum -y install authconfig-gtk
または、
# authconfig-tui
User Information の 「Use LDAP」 と Authentication の 「Use LDAP Authentication」にチェックを入れる。
Serverは、
ldap://IPアドレス/
Base DNは、
ou=People,dc=rukatan,dc=com
とりあえずログアウトして、inahou でログインできることを確認したらOK。
- memo
dn: Distinguished name dc: Domain Component cn: common name
参考文献: 毎日コミュニケーションズ CentOS サーバ構築バイブル