Linux Tips

既存のユーザーアカウントをLDAPサーバに登録するには

北浦訓行
2006/7/27

 LDAPでユーザー認証を行うと、複数のLinuxマシンのアカウントを一元的に管理できる。そのための準備として、LDAPサーバに既存のユーザーアカウントを登録する方法を説明する。LDAPサーバの設定やデータベースのエントリなどは、LinuxでLDAPサーバを構築するにはLDAPサーバへエントリを追加するにはの設定を使用する。

 最初に、ユーザーアカウントを登録するためのオブジェクトを作成する。ここでは、以下のようなファイルをbase.ldifとして作成した。

dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=example,dc=com
objectClass: organizationalUnit
ou: Group

 初めてLDAPサーバを立てる場合は、以下のようにする。

dn: dc=example,dc=com
objectClass: dcObject
objectclass: organization
dc: example
o: Example Corporation

dn: cn=Manager, dc=example,dc=com
objectClass: organizationalRole
cn:Manager

dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=example,dc=com
objectClass: organizationalUnit
ou: Group

 このオブジェクトを登録するために、ldapaddコマンドを実行する。なお、LinuxでLDAPサーバを構築するにはLDAPサーバへエントリを追加するにはではldapaddコマンドで直接パスワードを指定したが、今回は-Wオプションにより対話的にパスワードを入力している。

# ldapadd -f base.ldif -x -D "cn=Manager,dc=example,dc=com" -W
Enter LDAP Password: ←LDAPのパスワードを入力
adding new entry "ou=People,dc=example,dc=com"

adding new entry "ou=Group,dc=example,dc=com"

 次に、/etc/passwdファイルからユーザー情報を抽出する。数が少なければ、テキストエディタでも十分可能だ。多い場合は、grepコマンドなどで抽出する。一般ユーザーのユーザーIDは500番から始まるため、以下のように実行する。

# grep :5[0-9][0-9] /etc/passwd > user-list

 できあがったファイルは以下のようになる。

nori:x:500:500:nori:/home/nori:/bin/bash
foo:x:501:501:foo:/home/foo:/bin/bash
bar:x:502:502::/home/bar:/bin/bash

 続いて、/etc/passwdから抽出したファイルを元に、登録用のLDIFファイルを作成する。作成にはmigrate_passwd.plを使用するが、その前に/usr/share/openldap/migration/migrate_common.phの以下の個所を修正する。

# Default DNS domain
$DEFAULT_MAIL_DOMAIN = "padl.com";

# Default base
$DEFAULT_BASE = "dc=padl,dc=com";
      ↓
# Default DNS domain
$DEFAULT_MAIL_DOMAIN = "example.com";

# Default base
$DEFAULT_BASE = "dc=example,dc=com";

 修正が終わったら、migrate_passwd.plを実行する。MigrationToolsがインストールされていない場合は、yumコマンドでopenldap-serversパッケージをインストールする。

# /usr/share/openldap/migration/migrate_passwd.pl user-list > user-list.ldif

 同様にグループファイルの抽出と変換を行う。ここでは、groupというファイルに抽出して、group.ldifを作成した。

# /usr/share/openldap/migration/migrate_group.pl group > group.ldif

 最後に、作成したuser-list.ldifとgroup.ldifをldapaddコマンドで追加する。

# ldapadd -f user-list.ldif -x -D "cn=Manager,dc=example,dc=com" -W
Enter LDAP Password:
adding new entry "uid=nori,ou=People,dc=example,dc=com"

adding new entry "uid=foo,ou=People,dc=example,dc=com"

adding new entry "uid=bar,ou=People,dc=example,dc=com"

# ldapadd -f group.ldif -x -D "cn=Manager,dc=example,dc=com" -W
Enter LDAP Password:
adding new entry "cn=nori,ou=Group,dc=example,dc=com"

adding new entry "cn=foo,ou=Group,dc=example,dc=com"

adding new entry "cn=bar,ou=Group,dc=example,dc=com"

 以上で、ユーザーアカウントのLDAPサーバへの移行は完了だ。

Linux Tips Index



 Linux Squareフォーラム Linux Tipsカテゴリ別インデックス
インストール/RPM ブート/ブートローダ
ファイル操作 環境設定
ユーザー管理 コンソール/ターミナル
X Window System セキュリティ
トラブルシューティング 他OS関係
ネットワーク ハードウェア
Webサーバ Samba
GNOME KDE
OpenOffice.org エミュレータ
ソフトウェア そのほか/FAQ
全Tips公開順インデックス Linux Tips月間ランキング
Linux Squareフォーラム全記事インデックス

MONOist組み込み開発フォーラムの中から、Linux関連記事を紹介します


Linux & OSS フォーラム 新着記事
@ITメールマガジン 新着情報やスタッフのコラムがメールで届きます(無料)

注目のテーマ

Linux & OSS 記事ランキング

本日 月間