OpenLDAP를 사용한 중앙 집중형 인증 설정 매뉴얼
저자: Full-Stack Innovator Pro (기술 검토) 목표: Ubuntu 클라이언트에서 Single Sign-On(SSO)을 가능하게 하는 OpenLDAP 서버 구성...
작성자: Full-Stack Innovator Pro (기술 검토) 목표: Ubuntu Desktop 클라이언트에서 Single Sign-On(SSO)을 가능하게 하는 OpenLDAP 서버를 구성하고, 개인 홈 디렉터리 자동 생성 및 SSL/TLS 보안을 포함합니다.
- 도메인:
portelcore.local - 조직:
portelcore - 서버 (정적 IP):
172.20.0.153 - 클라이언트: Ubuntu 데스크탑
- 기본 DN:
dc=portelcore,dc=local
제1부: 서버 구성 (Ubuntu Server)
Sección titulada «PARTE 1: Configuración del Servidor (Ubuntu Server)»먼저 LDAP 디몬 (slapd) 및 관리 도구를 설치할 것입니다.
sudo apt updatesudo apt install slapd ldap-utils -y이제 특정 도메인으로 데이터베이스를 생성하기 위해 패키지를 재구성할 것입니다.
sudo dpkg-reconfigure slapd설정 도구에 대한 응답:
- 설정 건너뛰기?
No - DNS 도메인 이름?
portelcore.local - 조직 이름?
portelcore - 관리자 비밀번호? (안전한 비밀번호를 정의하고 기억하세요)
- 데이터베이스 엔진?
MDB - 삭제할 데이터베이스를 확인하시겠습니까?
No - 기존 데이터베이스를 이동하시겠습니까?
Sí
완료되면 데이터베이스가 올바르게 생성되었는지 도메인의 맥락을 확인할 것입니다.
slapcat | grep "dc=portelcore"2. 매핑 파일 생성 (LDIF)
Sección titulada «2. Creación del archivo de mapeo (LDIF)»이 단계는 디렉토리의 아키텍처를 정의하는 데 필수적입니다. 구조(조직 단위), 그룹 및 사용자를 정의하는 파일 .ldif을 생성할 것입니다.
파일을 생성합니다:
nano usuaris_grups.ldif다음 콘텐츠를 파일 내에 붙여넣습니다:
# Estructura Base: Unidades Organizativasdn: ou=people,dc=portelcore,dc=localobjectClass: organizationalUnitou: people
dn: ou=groups,dc=portelcore,dc=localobjectClass: organizationalUnitou: groups
# ---------------------------------------------------------# DEFINICIÓN DE GRUPOS# ---------------------------------------------------------
# Grupo 1: Administrador (GID 5000)dn: cn=Administrador,ou=groups,dc=portelcore,dc=localobjectClass: posixGroupcn: AdministradorgidNumber: 5000
# Grupo 2: Empleados (GID 5001)dn: cn=Empleats,ou=groups,dc=portelcore,dc=localobjectClass: posixGroupcn: EmpleatsgidNumber: 5001
# Grupo 3: Helpdesk (GID 5002)dn: cn=Helpdesk,ou=groups,dc=portelcore,dc=localobjectClass: posixGroupcn: HelpdeskgidNumber: 5002
# ---------------------------------------------------------# DEFINICIÓN DE USUARIOS# ---------------------------------------------------------
# Usuario 1: admin (Dentro de Administrador)dn: uid=admin,ou=people,dc=portelcore,dc=localobjectClass: inetOrgPersonobjectClass: posixAccountobjectClass: shadowAccountuid: adminsn: SystemgivenName: Administratorcn: Admin SystemdisplayName: Admin SystemuidNumber: 10000gidNumber: 5000userPassword: nolose123gecos: Admin SystemloginShell: /bin/bashhomeDirectory: /home/admin
# Usuario 2: user.portelcore (Dentro de Empleados)dn: uid=user.portelcore,ou=people,dc=portelcore,dc=localobjectClass: inetOrgPersonobjectClass: posixAccountobjectClass: shadowAccountuid: user.portelcoresn: UsergivenName: Portelcorecn: User PortelcoredisplayName: User PortelcoreuidNumber: 10001gidNumber: 5001userPassword: nolose123gecos: User PortelcoreloginShell: /bin/bashhomeDirectory: /home/user.portelcore
# Usuario 3: becario (Dentro de Helpdesk)dn: uid=becario,ou=people,dc=portelcore,dc=localobjectClass: inetOrgPersonobjectClass: posixAccountobjectClass: shadowAccountuid: becariosn: TechgivenName: Becariocn: Becario TechdisplayName: Becario TechuidNumber: 10002gidNumber: 5002userPassword: nolose123gecos: Becario TechloginShell: /bin/bashhomeDirectory: /home/becario3. 데이터베이스 가져오기
Sección titulada «3. Importación de la Base de Datos»LDAP 서버에 매핑 파일을 삽입할 것입니다.
ldapadd -x -D "cn=admin,dc=portelcore,dc=local" -W -f usuaris_grups.ldif1단계에서 설정한 관리자 암호를 요청할 것입니다.
확인:
모든 것이 올바르면 adding new entry 메시지가 표시됩니다. "becario" 사용자가 존재하는지 확인합니다:
aldapsearch -x -b "dc=portelcore,dc=local" "(uid=becario)"제2부: 클라이언트 설정 (Ubuntu 데스크탑)
Sección titulada «PARTE 2: Configuración del Cliente (Ubuntu Desktop)»클라이언트 머신으로 이동합니다. 이 컴퓨터에는 로컬로 생성된 사용자가 없으며, 서버에서 읽어야 합니다.
1. LDAP 클라이언트 설치
Sección titulada «1. Instalación del cliente LDAP»인증 시스템(PAM)과 이름 시스템(NSS)을 LDAP과 연결하기 위해 필요한 패키지를 설치할 것입니다.
sudo apt updatesudo apt install libnss-ldapd libpam-ldapd nscd -y그래픽 설치 프로그램 설정:
- LDAP 서버 URI:
ldap://172.20.0.153 - 검색 기준(Basic DN):
dc=portelcore,dc=local - 서비스: 스페이스바를 눌러
passwd,group및shadow를 선택해 주세요.
⚠️ 중요: nsswitch.conf 확인 설치 후 사용자가 작동하지 않으면 시스템이 LDAP을 검색하는지 수동으로 확인합니다:
cat /etc/nsswitch.conf | grep passwd만약 라인 끝에 ldap이라는 단어가 나타나지 않으면, 파일 sudo nano /etc/nsswitch.conf을 편집하고 ldap를 라인 passwd, group 및 shadow의 끝에 추가합니다.
클라이언트는 서버의 사용자를 "보는" 것이 가능해야 합니다.
getent passwd user.portelcore기대되는 결과: user.portelcore:x:10001:5001:User Portelcore:/home/user.portelcore:/bin/bash
PAM을 구성하여 처음 로그인 시 /home 폴더를 자동으로 생성하도록 합니다.
파일 common-session을 수정합니다:
sudo nano /etc/pam.d/common-session파일의 마지막에 이 줄을 추가합니다:
session required pam_mkhomedir.so skel=/etc/skel umask=0077메모리 캐시를 정리하기 위해 서비스 nscd을 재시작합니다:
sudo systemctl restart nscd제3부: 기본 테스트
Sección titulada «PARTE 3: Pruebas Básicas»데스크탑의 터미널에 사용자 admin (비밀번호: nolose123)로 로그인합니다.
id결과: uid=10000(admin)과 gid=5000(Administrador)이 표시되어야 합니다.
테스트 2: 그래픽 로그인 (SSO)
Sección titulada «Prueba 2: Inicio de Sesión Gráfico (SSO)»로그아웃하고 becario / nolose123로 다시 로그인합니다.
제4부: 서버 및 클라이언트 보안 (SSL/TLS)
Sección titulada «PARTE 4: Seguridad del Servidor y Cliente (SSL/TLS)»보안 규정을 준수하기 위해 연결을 암호화합니다.
4.1 인증서 생성 (서버에서)
Sección titulada «4.1 Generación de Certificados (En el Servidor)»OpenSSL를 설치하고 인증서를 생성합니다. 중요: 'Common Name (CN)'을 묻는다면 portelcore.local을 입력합니다.
sudo apt install openssl -ysudo mkdir /etc/ldap/certs
# 1. Crear clave privada CAsudo openssl genrsa -out /etc/ldap/certs/ca.key 2048
# 2. Crear certificado CA (Autoridad)sudo openssl req -x509 -new -nodes -key /etc/ldap/certs/ca.key -sha256 -days 3650 -out /etc/ldap/certs/ca.crt -subj "/C=ES/ST=Barcelona/L=Granollers/O=Portelcore/CN=portelcore.local"
# 3. Crear clave privada del Servidorsudo openssl genrsa -out /etc/ldap/certs/ldap_server.key 2048
# 4. Crear petición de firma (CSR)sudo openssl req -new -key /etc/ldap/certs/ldap_server.key -out /etc/ldap/certs/ldap_server.csr -subj "/C=ES/ST=Barcelona/L=Granollers/O=Portelcore/CN=portelcore.local"
# 5. Firmar el certificado del servidor con nuestra CAsudo openssl x509 -req -in /etc/ldap/certs/ldap_server.csr -CA /etc/ldap/certs/ca.crt -CAkey /etc/ldap/certs/ca.key -CAcreateserial -out /etc/ldap/certs/ldap_server.crt -days 365 -sha256LDAP가 키를 읽을 수 있도록 권한을 할당할 것입니다:
sudo chown -R openldap:openldap /etc/ldap/certs/sudo chmod 600 /etc/ldap/certs/*.key4.2 OpenLDAP의 TLS 사용 설정 (서버)
Sección titulada «4.2 Configuración de OpenLDAP para usar TLS (Servidor)»인증서가 있는 위치를 지정하기 위해 tls_config.ldif 파일을 만들겠습니다:
nano tls_config.ldif내용:
dn: cn=configchangetype: modifyreplace: olcTLSCACertificateFileolcTLSCACertificateFile: /etc/ldap/certs/ca.crt-replace: olcTLSCertificateFileolcTLSCertificateFile: /etc/ldap/certs/ldap_server.crt-replace: olcTLSCertificateKeyFileolcTLSCertificateKeyFile: /etc/ldap/certs/ldap_server.key설정을 적용하겠습니다:
sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f tls_config.ldif/etc/default/slapd를 편집하여 안전한 연결을 허용하는지 확인하겠습니다:
sudo nano /etc/default/slapdSLAPD_SERVICES를 찾아 다음과 같이 설정합니다:
SLAPD_SERVICES="ldap:/// ldapi:/// ldaps:///"
재시작하겠습니다:
sudo systemctl restart slapd4.3 클라이언트의 SSL 설정 (Ubuntu 데스크탑)
Sección titulada «4.3 Configuración del Cliente para SSL (Ubuntu Desktop)»⚠️ 사전 필수 단계: DNS 구성
인증서가 portelcore.local에 대해 발급되었으므로 SSL 구성에서 IP를 직접 사용할 수 없습니다.
-
클라이언트의 hosts 파일을 편집하겠습니다:
Ventana de terminal sudo nano /etc/hosts -
이 줄을 맨 아래에 추가할 것입니다:
172.20.0.153 portelcore.local
SSL 설정 단계:
-
CA 전송: 서버에서 클라이언트로 인증서를 다운로드해야 합니다.
클라이언트에서 터미널을 열고 다음을 실행합니다: (
usuari_remot를 서버 사용자로 대체합니다. 예를 들어alex)Ventana de terminal # 1. Descargar archivoscp user.portelcore@172.20.0.153:/etc/ldap/certs/ca.crt .# 2. Mover al lugar correctosudo mv ca.crt /etc/ssl/certs/# 3. Asignar permisos de lectura para todossudo chmod 644 /etc/ssl/certs/ca.crt -
LDAP 데몬 구성: 구성 파일을 편집합니다:
Ventana de terminal sudo nano /etc/nslcd.conf중요한 두 가지 변경 사항을 수행합니다:
변경 A: URI를 IP 대신 도메인 이름을 사용하도록 수정합니다:
uri ldap://portelcore.local변경 사항 B: TLS 및 인증서를 활성화합니다:
ssl start_tlstls_reqcert demandtls_cacertfile /etc/ssl/certs/ca.crt -
클라이언트 서비스 재시작:
Ventana de terminal sudo systemctl restart nslcd -
연결 확인:
getent passwd admin
제5부: 전문가 감사 (tcpdump + Wireshark)
Sección titulada «PARTE 5: Auditoría Profesional (tcpdump + Wireshark)»생산 환경 (GUI가 없는 서버)에서는 서버에서 트래픽을 캡처하고 나중에 데스크탑 컴퓨터에서 분석하는 것이 좋은 실천입니다.
5.1 트래픽 캡처 (서버에서)
Sección titulada «5.1 Captura de Tráfico (En el Servidor)»-
캡처 도구를 설치하겠습니다:
Ventana de terminal sudo apt install tcpdump -y -
LDAP 포트(389)를 필터링하여 캡처를 시작하고
.pcap에 저장하겠습니다:Ventana de terminal sudo tcpdump -i any port 389 -w /tmp/ldap_capture.pcap(다음 단계를 수행하는 동안 터미널을 열어 둡니다).
5.2 트래픽 생성 (클라이언트에서)
Sección titulada «5.2 Generación de Tráfico (En el Cliente)»-
클라이언트(Ubuntu Desktop)에서 터미널을 열겠습니다.
-
트래픽을 생성하기 위해 쿼리를 수행하겠습니다:
getent passwd user.portelcore -
서버로 돌아가서
Ctrl + C로 캡처를 중지합니다.
5.3 파일 분석 (클라이언트에서)
Sección titulada «5.3 Análisis del Archivo (En el Cliente)»이제 캡처 파일을 클라이언트로 전송하여 Wireshark(그래픽 환경이 있는 도구)로 분석할 것입니다.
-
클라이언트에서 파일을 다운로드할 것입니다:
scp usuari@172.20.0.153:/tmp/ldap_capture.pcap . -
Wireshark을 설치하고 열겠습니다:
Ventana de terminal sudo apt install wireshark -ywireshark ldap_capture.pcap
무엇을 찾아야 하나요?
- 프로토콜
LDAP을 가진 패킷을 찾아볼 것입니다. - "startTLSRequest" 패킷을 찾아볼 것입니다.
- 그 직후, TLSv1.2 또는 TLSv1.3 패킷이 나타날 것입니다.
- 성공 테스트: "Application Data" 패킷의 내용을 읽어보려고 합니다. 단지 해독할 수 없는 문자(암호화된)만 보인다면, 보안이 올바르게 작동합니다.
부록 1: 서버의 IP 주소가 변경된 경우 해결 방법
Sección titulada «ANEXO 1: Solución si cambia la IP del Servidor» 클라이언트가 이미 설정되어 있고 서버의 IP가 변경된 경우(예: 192.168.1.100에서 172.20.0.153로), 재설치할 필요가 없습니다.
옵션 A (권장 - 마법사):
nslcd 패키지 재구성을 실행합니다:
sudo dpkg-reconfigure nslcdURI(ldap://172.20.0.153)가 요청될 때 새로운 IP를 입력합니다.
선택지 B (수동):
-
nslcd 데몬 설정 파일을 편집합니다:
Ventana de terminal sudo nano /etc/nslcd.conf -
URI 줄 수정:
uri로 시작하는 줄을 찾아 이전 IP를 새 IP로 변경합니다. 변경 전:uri ldap://192.168.1.100변경 후:uri ldap://172.20.0.153(Ctrl+O로 저장하고 Ctrl+X로 나갑니다)
-
변경 사항을 적용하기 위해 서비스를 재시작합니다:
Ventana de terminal sudo systemctl restart nslcdsudo systemctl restart nscd -
연결을 확인합니다:
getent passwd user.portelcore
부록 2: 문제 해결 (Troubleshooting)
Sección titulada «ANEXO 2: Resolución de Problemas (Troubleshooting)»getent passwd이 아무것도 반환하지 않지만 네트워크 연결이 있는 경우, 문제는 일반적으로 SSL입니다.
1단계: 실시간 진단 데몬을 중지하고 디버그 모드에서 수동으로 실행하여 연결 거부 이유를 확인합니다.
sudo systemctl stop nslcdsudo nslcd -d최근 줄을 읽습니다. "hostname does not match CN"을 보면, 구성 파일에 IP 주소가 이름 대신 입력된 것입니다.
2단계: URI 확인
/etc/nslcd.conf에 다음이 정확히 있는지 확인합니다:
uri ldap://portelcore.local
(ldap://172.20.0.153가 있으면 인증서가 실패합니다).

