변군이글루

[LDAP] OpenLDAP 스크립트로 그룹 생성 및 사용자 계정 본문

* 리눅스

[LDAP] OpenLDAP 스크립트로 그룹 생성 및 사용자 계정

변군 변군이글루 2021. 6. 13. 20:07
728x90

OpenLDAP 스크립트로 그룹 생성 및 사용자 계정

그룹 아이디 생성

$ cat ldapGroupAddv3.sh
#!/bin/bash

# GroupName, GidNumber
echo "dn: cn=$1,ou=Groups,dc=4wxyz,dc=com
changetype: add
objectClass: top
objectClass: posixGroup
#objectClass: groupOfUniqueNames
gidNumber: $2
cn: $1
#uniqueMember: <DN of member>
#memberUid: 1501
description: groups" > .tmp/$1-group.ldif

#DATA Insert
docker exec openldap ldapmodify -a -x \
-D cn=admin,dc=4wxyz,dc=com \
-H ldap://127.0.0.1 \
-w ldappassword \
-f /container/service/slapd/assets/custome/.tmp/$1-group.ldif

#DATE Search
echo "DATE Search :"
docker exec openldap ldapsearch -x -b dc=4wxyz,dc=com -D "cn=admin,dc=4wxyz,dc=com" \
-w ldappassword -LLL -Z dn | egrep $1

그룹 이름: apart, GID : 2110

$ ./ldapGroupAddv3.sh apart 2100
--output--
adding new entry "cn=apart,ou=Groups,dc=4wxyz,dc=com"

DATE Search :
dn: cn=apart,ou=Groups,dc=4wxyz,dc=com

사용자 계정 생성

#!/bin/bash

# FirstName, UserName, UIDNumber, E-Mail
echo "dn: uid=$2,ou=People,dc=4wxyz,dc=com
uid: $2
cn: $1
sn: $1
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetorgperson
objectClass: posixAccount
givenName: $1
mail: $4@4wxyz.com
gecos: $1
loginShell: /bin/bash
uidNumber: $3
gidNumber: $3
homeDirectory: /home/$2
userPassword: {SSHA}UZrWRlhxpXK+aAfPGz5B+wloR+Iaw9TV
description: User Create" > .tmp/$2-user.ldif

#DATA Insert
docker exec openldap ldapmodify -a -x \
-D cn=admin,dc=4wxyz,dc=com \
-H ldap://127.0.0.1 \
-w ldappassword \
-f /container/service/slapd/assets/custome/.tmp/$2-user.ldif

#DATE Search
echo "DATE Search :"
docker exec openldap ldapsearch -x -b dc=4wxyz,dc=com -D "cn=admin,dc=4wxyz,dc=com" \
-w ldappassword -LLL -Z dn | egrep $2

사용자 이름: sangchul, 아이디: scbyun, UID: 2101, 이메일: scbyun

$ ./ldapUserAddv3.sh sangchul scbyun 2101 scbyun
--output--
adding new entry "uid=scbyun,ou=People,dc=4wxyz,dc=com"

DATE Search :
dn: uid=scbyun,ou=People,dc=4wxyz,dc=com
728x90
Tag
,
0 Comments
댓글쓰기 폼