14
13

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 5 years have passed since last update.

【LDAP環境構築:4】 ユーザーLDIF作成から登録まで

Posted at

#####LDAP サーバーへのデータの登録

ユーザー追加用LDIFファイル作成スクリプトの用意
touch /etc/openldap/tmp/create_user_ldif.sh
chmod 700 /etc/openldap/tmp/create_user_ldif.sh
vi /etc/openldap/tmp/create_user_ldif.sh
create_user_ldif.sh
#!/bin/sh
>
read -p "ベースDN(例:dc=example,dc=com) : " BASE_DN_NAME
read -p "ユーザー名(例:testuser)        : " USER_NAME
read -p "ユーザーID(例:1001)            : " USER_ID
read -p "グループID(例:1001)            : " GROUP_ID
read -p "ユーザーパスワード(例:pass)    : " USER_PASSWORD
read -p "Home Directory(/home/testuser) : " USER_DIRECTORY
>
PASSWORD=$(slappasswd -s "${USER_PASSWORD}")
>
echo "
dn: uid=${USER_NAME},ou=People,${BASE_DN_NAME}
uid: ${USER_NAME}
cn: ${USER_NAME}
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: ${PASSWORD}
shadowLastChange: 15862
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: ${USER_ID}
gidNumber: ${GROUP_ID}
homeDirectory: ${USER_DIRECTORY}
"
ユーザー追加用LDIFファイル作成
/etc/openldap/tmp/create_user_ldif.sh > /etc/openldap/tmp/user.ldif
ベースDN(例:dc=example,dc=com) : dc=example,dc=com
ユーザー名(例:testuser)        : testuser
ユーザーID(例:1001)            : 9999
グループID(例:1001)            : 9999
ユーザーパスワード(例:pass)    : pass
Home Directory(/home/testuser) : /home/testuser
ユーザー追加用LDIFファイルの登録
ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f /etc/openldap/tmp/user.ldif
    adding new entry "uid=testuser,ou=People,dc=example,dc=com"
確認
ldapsearch  -x -b 'dc=example,dc=com' 'uid=testuser'
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: uid=testuser
# requesting: ALL
#
# testuser, People, example.com
dn: uid=testuser,ou=People,dc=example,dc=com
uid: testuser
cn: testuser
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowLastChange: 15862
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 9999
gidNumber: 9999
homeDirectory: /home/testuser
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
後片付け
rm /etc/openldap/tmp/user.ldif
14
13
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
14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?