13 February 2008

OpenLDAP設定 on Fedora 8

OpenLDAPサーバ&クライアントのインストール


[root@localhost ~]# yum install openldap-servers

[root@localhost ~]# yum install openldap-clients

管理者パスワードを作成


[root@localhost ~]# /usr/sbin/slappasswd -s my_password -h {MD5}
{MD5}IjismUmwkxue2MLw90scoQhcQ==

設定ファイルの編集

/etc/openldap/slapd.conf

access to * ← アクセス権の設定
by dn="cn=Manager, dc=localhost, dc=localdomain" write
by self write
by * read

database bdb ← データベース形式
suffix "dc=localhost,dc=localdomain" ← データベース識別名
rootdn "cn=Manager,dc=localhost,dc=localdomain" ← 管理者識別名

# rootpw secret
rootpw {MD5}IjismUmwkxue2MLw90scoQhcQ== ← 管理者(Manager)パスワード

BDB形式データベースの設定ファイルをコピーする


[root@localhost ~]# cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

ベースとなるオブジェクト、管理者名を設定するためのファイルを作る

~/base.ldif

# LDAP root
dn: dc=localhost, dc=localdomain
objectClass: dcObject
objectClass: organization
o: S5040 LDAP Organization
dc: localhost
description: LDAP top level

# 管理者 (slapd.conf の rootdn で設定した管理者 Manager の設定)
dn: cn=Manager, dc=localhost, dc=localdomain
objectClass: organizationalRole
cn: Manager
description: LDAP Management User

# ユーザアカウント登録用オブジェクト
dn: ou=People, dc=localhost, dc=localdomain
objectClass: organizationalUnit
ou: People

# ユーザグループ登録用オブジェクト
dn: ou=Group, dc=localhost, dc=localdomain
objectClass: organizationalUnit
ou: Group

LDAPサーバに登録する


[root@localhost ~]# ldapadd -h localhost -x -D "cn=Manager, dc=localhost, dc=local
domain" -W -f base.ldif

登録されたツリーの確認と、削除方法


[root@localhost ~]# ldapsearch -x -b "dc=localhost, dc=localdomain"

[root@localhost ~]# ldapdelete -h localhost -x -D "cn=Manager, dc=localhost, dc=lo
caldomain" -W "ou=Users, dc=localhost, dc=localdomain"

グループの新規作成

~/group01.ldif

dn: cn=Group01, ou=Group, dc=localhost, dc=localdomain
cn: Group01
objectClass: posixGroup
gidNumber: 1101

LDAPデータベースに追加


[root@localhost ~]# ldapadd -h localhost -x -D "cn=Manager, dc=localhost, dc=local
domain" -W -f group01.ldif
Enter LDAP Password:
adding new entry "cn=Group01, ou=Group, dc=localhost, dc=localdomain"

ユーザの新規追加

~/group01.ldif

dn: uid=user01, ou=People, dc=localhost, dc=localdomain
changetype: add
uid: user01
cn: user01
sn: user01
objectClass: person
objectClass: posixAccount
objectClass: inetOrgPerson
userPassword: {MD5}t1cF1+NecBRSGka1MiNuww==
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1101
homeDirectory: /home/user01

dn: cn=Group01, ou=Group, dc=localhost, dc=localdomain
changetype: modify
add: memberUid
memberUid: user01

LDAPデータベースに追加


[root@localhost ~]# ldapadd -h localhost -x -D "cn=Manager, dc=localhost, dc=local
domain" -W -f user01.ldif
Enter LDAP Password:
adding new entry "uid=user01, ou=People, dc=localhost, dc=localdomain"

modifying entry "cn=Group01, ou=Group, dc=localhost, dc=localdomain"

LDAPをLinuxログインの認証に使う設定


[root@localhost ~]# authconfig-tui

ユーザ情報:LDAPを使用、認証:LDAP認証を使用 にチェック(アスタリスク)を設定する。
この設定は、/etc/nsswitch.conf と /etc/ldap.conf に入力される。