3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenLDAPの管理コマンド

Posted at

#OpenLDAPの主なデータ管理コマンド

コマンド名 役割
ldapadd LDAPディレクトリにエントリを追加します
ldapmodify LDAPエントリのデータを修正します
ldapmodrdn LDAPエントリのRDNを変更します
ldapdelete LDAPエントリを削除します
ldapsearch LDAPエントリを検索し、表示します
ldapcompare LDAPエントリに登録されている属性値と値を比較します
ldappasswd LDAPエントリに登録されているパスワードを変更します
ldapwhoami LDAPサーバにwhoami処理を行います
#LDAPエントリの検索・表示(ldapsearch)
実際のコマンド例:
ou=People,dc=example,dc=comをベースDNにエントリを検索する

-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定
-b 検索を開始するベースDNを指定
-LLL 検索結果の表示方法を指定
(objectClass=*) 検索のフィルタとして指定しておりすべてのエントリに必須の属性なので実質すべてのエントリが表示される

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

#LDAPエントリの追加(ldapadd)
実際のコマンド例:
ou=People,dc=example,dc=comのエントリの配下にTaroというユーザーのエントリを追加

Taroを追加するためのLDIFファイルを用意
※taropasswd

# cat /usr/local/etc/openldap/ldif/taro.ldif
dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: Person
cn: Taro
sn: Example Taro
userPassword: {SSHA}tbrQ0PzsZgBugRkl/QbhOuh1rSRi0e69

ldapaddコマンドで追加
-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定
-f 登録するデータを指定

# ldapadd -x -D 'cn=Manager,dc=example,dc=com' -W -f /usr/local/etc/openldap/ldif/taro.ldif
Enter LDAP Password:
adding new entry "cn=taro,ou=People,dc=example,dc=com"

ldapsearchコマンドで確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: person
cn: Taro
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=

#LDAPエントリの削除(ldapdelete)
実際のコマンド例:
"cn=Taro,ou=People,dc=example,dc=com"のエントリを削除

-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定

# ldapdelete -x -D "cn=Manager,dc=example,dc=com" -W cn=Taro,ou=People,dc=example,dc=com
Enter LDAP Password:

ldapsearchコマンドで確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

#LDAPエントリの修正(ldapmodify)
##属性の追加
実際のコマンド例
"cn=Taro,ou=People,dc=example,dc=com"のエントリに属性"description"を追加

ldapsearchコマンドで現状確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: person
cn: Taro
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=

Taroのエントリに"description"属性を追加するLDIFファイルを用意

# cat /usr/local/etc/openldap/ldif/taro-modify.ldif
dn: cn=Taro,ou=People,dc=example,dc=com
changetype: modify
add: description
description: He is the member of marketing group.

ldapmodifyコマンドでエントリを追加
-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定

# ldapmodify -x -D "cn=Manager,dc=example,dc=com" -W -f /usr/local/etc/openldap/ldif/taro-modify.ldif
Enter LDAP Password:
modifying entry "cn=Taro,ou=People,dc=example,dc=com"

ldapsearchコマンドで確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: person
cn: Taro
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=
description: He is the member of marketing group.

##属性の削除
実際のコマンド例:
"cn=Taro,ou=People,dc=example,dc=com"のエントリに属性"description"を削除

Taroのエントリから"description"属性を削除するLDIFファイルを用意

# cat /usr/local/etc/openldap/ldif/taro-modify2.ldif
dn: cn=Taro,ou=People,dc=example,dc=com
changetype: modify
delete: description

ldapmodifyコマンドで属性を削除
-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定

# ldapmodify -x -D "cn=Manager,dc=example,dc=com" -W -f /usr/local/etc/openldap/ldif/taro-modify2.ldif
Enter LDAP Password:
modifying entry "cn=Taro,ou=People,dc=example,dc=com"

ldapsearchコマンドで確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: person
cn: Taro
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=

##属性値の変更
実際のコマンド例:
"cn=Taro,ou=People,dc=example,dc=com"の属性"description"の値を修正

ldapsearchコマンドで現状確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: person
cn: Taro
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=
description: He is the member of marketing group.

Taroのエントリの"description"属性の値を修正するLDIFファイルを用意

# cat /usr/local/etc/openldap/ldif/taro-modify3.ldif
dn: cn=Taro,ou=People,dc=example,dc=com
changetype: modify
replace: description
description: He is the member of sales group.

ldapmodifyコマンドで属性"description"の値を修正
-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定

# ldapmodify -x -D "cn=Manager,dc=example,dc=com" -W -f /usr/local/etc/openldap/ldif/taro-modify3.ldif
Enter LDAP Password:
modifying entry "cn=Taro,ou=People,dc=example,dc=com"

ldapsearchコマンドで確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Taro,ou=People,dc=example,dc=com
objectClass: person
cn: Taro
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=
description: He is the member of sales group.

#RDNの修正(ldapmodrdn)
ldapmodifyではRDNの修正することは不可

実際のコマンド例:
"cn=Taro,ou=People,dc=example,dc=com"のcn属性を変更し、
"cn=Hanako,ou=People,dc=example,dc=com"にする

-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定
-r 以前のRDNの値を保存せずに削除

# ldapmodrdn -x -D "cn=Manager,dc=example,dc=com" -W -r "cn=Taro,ou=People,dc=example,dc=com" "cn=Hanako"
Enter LDAP Password:

ldapsearchコマンドで確認

# ldapsearch -x -D 'cn=Manager,dc=example,dc=com' -W -LLL -b 'ou=People,dc=example,dc=com' '(objectClass=*)'
Enter LDAP Password:
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: cn=Hanako,ou=People,dc=example,dc=com
objectClass: person
sn: Example Taro
userPassword:: e1NTSEF9dGJyUTBQenNaZ0J1Z1JrbC9RYmhPdWgxclNSaTBlNjk=
description: He is the member of sales group.
cn: Hanako

#属性値の比較(ldapcompare)
実際のコマンド例:
"cn=Hanako,ou=People,dc=example,dc=com"のcn属性に"Taro"という値が設定されている項目があるかをチェック
指定した属性値が設定されていればTRUE、設定されていなければFALSEが表示
-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定

# ldapcompare -x -D "cn=Manager,dc=example,dc=com" -W 'cn=Hanako,ou=People,dc=example,dc=com' 'cn: Taro'
Enter LDAP Password:
FALSE

実際のコマンド例:
"cn=Hanako,ou=People,dc=example,dc=com"のcn属性に"Hanako"という値が設定されている項目があるかをチェック
指定した属性値が設定されていればTRUE、設定されていなければFALSEが表示
-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定

# ldapcompare -x -D "cn=Manager,dc=example,dc=com" -W 'cn=Hanako,ou=People,dc=example,dc=com' 'cn: Hanako'
Enter LDAP Password:
TRUE

#パスワード属性の変更(ldappasswd)
実際のコマンド例:
"cn=Hanako,ou=People,dc=example,dc=com"のパスワードを変更
※taropasswd → hanakopasswd

-x 簡易認証
-D ルートDNを指定
-W パスワードをプロンプトから入力する指定
-S 新しいパスワードをプロンプトから入力

# ldappasswd -x -D "cn=Manager,dc=example,dc=com" -W 'cn=Hanako,ou=People,dc=example,dc=com' -S
New password:
Re-enter new password:
Enter LDAP Password:

ここまで

#参考
・『入門LDAP/OpenLDAP ディレクトリサービス導入・運用ガイド 第3版』

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?