Archive for the ‘LDAP’ Category

ติดตั้ง openldap บน ubuntu 24.04

ติดตั้ง OpenLDAP บน Ubuntu 24.04

1: อัปเดตระบบ

root@ldapserv:~# apt update && sudo apt upgrade -y

2: ติดตั้ง OpenLDAP และเครื่องมือที่เกี่ยวข้อง

root@ldapserv:~# apt install slapd ldap-utils -y
ระบบจะติดตั้ง slapd (OpenLDAP server) และ ldap-utils (เครื่องมือ CLI)
>> ใน Ubuntu 24.04 อาจไม่มี prompt ให้กำหนดรหัสผ่านของ admin (cn=admin) ในระหว่างติดตั้ง
Configuring slapd
Please enter the password for the admin entry in your LDAP directory.

Administrator password: xxxxx

3: ตั้งค่ารหัสผ่านสำหรับ LDAP admin ด้วย dpkg-reconfigure

ตั้งค่า config สำหรับ OPENLDAP ใหม่
root@ldapserv:~# dpkg-reconfigure slapd

คำถามที่คุณจะเจอ:
1. Omit OpenLDAP server configuration? → เลือก No
2. DNS domain name: → เช่น example.com
3. Organization name: → เช่น Example Inc
4. Administrator password: → ตั้งรหัสผ่าน
5. Database backend to use: → เลือก MDB (ค่าเริ่มต้น)
6. Remove the database when slapd is purged? → No
7. Move old database? → Yes

หลังจากนั้นระบบจะตั้งค่าฐานข้อมูลให้ใหม่ทั้งหมด
root@ldapserv:~# netstat -lntp
Active Internet connections (only servers)

tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 17736/slapd <–OPENLDAP
tcp6 0 0 :::22 :::* LISTEN 823/sshd: /usr/sbin
tcp6 0 0 :::389 :::* LISTEN 17736/slapd

 

4: ทดสอบ LDAP ด้วย ldapsearch ตัวอย่าง omtel.co.th

การ search ข้อมูลจาก LDAP server เช่น omtelldap.omtel.co.th จำเป็นต้องทราบ:
1.Base DN (จุดเริ่มต้นของ directory tree ที่จะค้นหา เช่น dc=omtel,dc=co,dc=th)
2.Credentials (ถ้าต้อง bind ด้วย user/password)
3.Port ที่ใช้ (ปกติ 389 สำหรับ LDAP หรือ 636 สำหรับ LDAPS)
4.Filter ที่ต้องการค้นหา เช่น (objectClass=person) หรือ (uid=someone)

root@ldapserv:~# ldapsearch -x -H ldap://localhost \
-D “cn=admin,dc=omtel,dc=co,dc=th” -w ‘LDAP Password’ \
-b “dc=omtel,dc=co,dc=th”

# extended LDIF
#
# LDAPv3
# base <dc=omtel,dc=co,dc=th> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# omtel.co.th
dn: dc=omtel,dc=co,dc=th
objectClass: top
objectClass: dcObject
objectClass: organization
o: omptelldap
dc: omtel

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

แบบนี้ถือว่าสำเร็จแล้ว!

การตอบกลับจาก ldapsearch ของคุณ:
•แสดงว่าเชื่อมต่อกับ LDAP server ได้สำเร็จ (result: 0 Success)
•มีการคืนค่า entry ของ dc=omtel,dc=co,dc=th ได้ 1 รายการ (root entry ของ directory tree)
•ไม่มี error ใด ๆ เช่น invalid credentials หรือ no such object

ขั้นตอนถัดไป (หากต้องการ):


5. หากต้องการ:

•สร้าง OU (organizationalUnit) เช่น People, Groups
•เพิ่มผู้ใช้ เช่น uid=tee,ou=People,…
ให้ใช้ไฟล์ .ldif เช่น:

ตัวอย่าง: add_base.ldif

dn: ou=People,dc=omtel,dc=co,dc=th
objectClass: organizationalUnit
ou: People

dn: uid=tee,ou=People,dc=omtel,dc=co,dc=th
objectClass: inetOrgPerson
cn: Naitinoi Sak
sn: Sak
uid: tee
userPassword: {SSHA} password

root@ldapserv:~# ldapadd -x -D “cn=admin,dc=omtel,dc=co,dc=th” -w ‘LDAP Password’ -f add_base.ldif
adding new entry “ou=People,dc=omtel,dc=co,dc=th”

adding new entry “uid=tee,ou=People,dc=omtel,dc=co,dc=th”

สามารถ Connect Test จากโปรแกรม LDAP Client Test เช่น
https://jxplorer.org/downloads/users.html
https://sourceforge.net/projects/ldapadmin/files/ldapadmin/1.8.3/