본문 바로가기
인프라/리눅스

[Centos7] OpenLDAP 구축

by IT맥구리나스 2022. 6. 13.

AWX LDAP인증을 위한 Centos7에 OpenLDAP를 구축한다.

 

구축방법

## yum 패키지 설치
yum install -y compat-openldap openldap openldap-servers openldap-clients openldap-servers-sql openldap-devel

## Open LDAP 테이터베이스 설정
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap. /var/lib/ldap/DB_CONFIG

## 서비스 등록 및 시작

systemctl --now enable slapd.service


## OpenLDAP 루트 사용자 비밀번호 설정
slappasswd -h {SSHA} -s wkawhawkwk1!
# 수행결과
{SSHA}PUombelqqxw2JkU0wfWGBrgccLtZktdA

## chrootpw.ldif 파일 생성
cat <<EOF > chrootpw.ldif
dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}PUombelqqxw2JkU0wfWGBrgccLtZktdA
EOF


## OpenLDAP 스키마 추가

ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif

##chdomain.ldif 파일 생성 , cn(admin)는 관리자계정, dc(testseo)는 사이트 도메인주소, olcRootPW는 아까 생성된 값으로 변경한다.

cat <<EOF > chdomain.ldif
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth"
  read by dn.base="cn=admin,dc=testseo,dc=com" read by * none

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=testseo,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=admin,dc=testseo,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}PUombelqqxw2JkU0wfWGBrgccLtZktdA

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
  dn="cn=admin,dc=testseo,dc=com" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=admin,dc=testseo,dc=com" write by * read
EOF

## 실행
ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif



## basedomain.ldif  생성
cat <<EOF > basedomain.ldif
dn: dc=testseo,dc=com
o: testseo
dc: testseo
objectClass: top
objectClass: dcObject
objectclass: organization

dn: cn=admin,dc=testseo,dc=com
objectClass: organizationalRole
cn: admin
description: Directory admin

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

dn: ou=Group,dc=testseo,dc=com
objectClass: organizationalUnit
ou: Group
EOF

## 실행
 ldapadd -x -D cn=admin,dc=testseo,dc=com -W -f basedomain.ldif


## useradd.ldif(유저 생성파일)  생성
cat <<EOF > useradd.ldif
dn: uid=magnus,ou=People,dc=testseo,dc=com
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: testuser
uid: testuser
uidNumber: 1500
gidNumber: 1500
homeDirectory: /home/testuser
loginShell: /bin/bash
gecos: Linuxuser [Admin (at) HostAdvice]
userPassword: {crypt}x
shadowLastChange: 17058
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
EOF

## 실행
ldapadd -x -D cn=admin,dc=testseo,dc=com -W -f useradd.ldif

 

확인방법

- LDAP ADMIN이라는 프로그램을 통하여 접속확인을 해본다. 다운로드 주소는 아래(무설치 실행파일)

https://sourceforge.net/projects/ldapadmin/

 

LDAP Admin

Download LDAP Admin for free. Windows LDAP editor, includes support for POSIX groups and accounts, SAMBA accounts, some Postfix objects and more

sourceforge.net

 

아래와 같이 설정하여 접속시도를 해본다.

아까 useradd.ldif로 만들었던 magnus 계정까지 잘있는 것을 확인 할 수 있다.

해당툴로 쉽게 계정생성도 가능하다.

 

반응형

댓글