既にLDAPサーバ構築にてトップドメインの定義が終わって、ユーザとグループの枠が既にある。
ここではこの枠にデータを流し込む
まずはグループから登録する
過去記事LDAP/データ登録181006
ここではxrayとem、そしてadminグループを登録してみます。
下記のようなLDIFファイル(group.ldif)を作ります。
複数のデータを登録するには空行を挟みます。
[root@ldap-server ~]# vi ldap/group.ldif
dn: cn=xray,ou=group,dc=sybyl,dc=local
objectClass: posixGroup
cn: xray
gidNumber: 2001
dn: cn=em,ou=group,dc=sybyl,dc=local
objectClass: posixGroup
cn: em
gidNumber: 2002
dn: cn=admin,ou=group,dc=sybyl,dc=local
objectClass: posixGroup
cn: admin
gidNumber: 2003
[root@ldap-server ~]#
これをldapaddコマンドで登録します
[root@ldap-server ~]# ldapadd -x -D cn=Manager,dc=sybyl,dc=local -W -f ldap/group.ldif
Enter LDAP Password:
adding new entry "cn=xray,ou=group,dc=sybyl,dc=local"
adding new entry "cn=em,ou=group,dc=sybyl,dc=local"
adding new entry "cn=admin,ou=group,dc=sybyl,dc=local"
[root@ldap-server ~]#
一方で下記のようなエラーが発生する場合がある
[root@ldap-server ~]# ldapadd -x -D cn=Manager,dc=sybyl,dc=local -W -f ldap/group.ldif
Enter LDAP Password:
ldapadd: attributeDescription "dn": (possible missing newline after line 10, entry "cn=xray,ou=group,dc=sybyl,dc=local"?)
ldapadd: attributeDescription "dn": (possible missing newline after line 11, entry "cn=xray,ou=group,dc=sybyl,dc=local"?)
adding new entry "cn=xray,ou=group,dc=sybyl,dc=local"
ldap_add: Type or value exists (20)
additional info: objectClass: value #0 provided more than once
[root@ldap-server ~]#
この際は、入力に使ったファイルを調べます。大抵は上記をコピペした場合は空行にスペースがあるためにエラーとなります。
[root@ldap-server ~]# od -c ldap/group.ldif
:
0000100 n : x r a y \n g i d N u m b e -->「n: xray\ngidNumbe」
0000120 r : 2 0 0 1 \n \n d n : c n -->「r: 2001\n \ndn: cn」 <-- \nと\nの間に隙間がある. これを削除します
0000140 = e m , o u = g r o u p , d c =
:
[root@ldap-server ~]#
空行のスペースを削除しして再度インポートを行います
LDAP Adminから参照すると下記のようになる。
グループが出来たので、次はユーザです。
ユーザ登録用のLDIFファイル(foo.ldif)を用意します。
一つのLDIFファイルに複数のユーザ情報を記載しても構わないのですが、一人1枚で作ってみます。
記載内容ですが、「ou=People」に対してはユーザfooの追加(add)行為で、
「ou=Group」に対してはグループxrayへの修正(modify)行為となる事に注意
*userPasswordの値はslappasswdコマンドで作成
[root@ldap-server ~]# cat ldap/foo.ldif
dn: uid=foo,ou=people,dc=sybyl,dc=local
changetype: add
objectClass: person
objectClass: posixAccount
objectClass: inetOrgPerson
objectClass: shadowAccount
uid: foo
cn: foo sybyl
sn: foo
givenName: sybyl
mail: foo@sybyl.local
uidNumber: 3000
gidNumber: 2001
homeDirectory: /home/foo
userPassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
loginShell: /bin/bash
shadowLastChange: 10000
shadowMin: 0
shadowMax: 99999
shadowWarning: 14
shadowInactive: 99999
shadowExpire: -1
dn: cn=xray,ou=Group,dc=sybyl,dc=local
changetype: modify
add: memberUid
memberUid: foo
[root@ldap-server ~]#
そして同様にldapaddコマンドでデータを登録します
[root@ldap-server ~]# ldapadd -x -D cn=Manager,dc=sybyl,dc=local -W -f ldap/foo.ldif
Enter LDAP Password:
adding new entry "uid=foo,ou=people,dc=sybyl,dc=local"
modifying entry "cn=xray,ou=Group,dc=sybyl,dc=local"
[root@ldap-server ~]#
LDAP Adminから「ou=People」確認すると
となる。
また「ou=Group」では「cn=xray」に登録されている