ใช้ LDAP Authentication Client บน Ubuntu


Posted in:

ลูกค้ารายหนึ่งของผมต้องการให้ Mail Server ที่ติดตั้งไว้แล้วเป็นตัว Authenticate ให้กับ application อื่นๆ บน Server หลัก เนื่องจากผู้ใช้เล่นบอก password ของตัวเองกับคนอื่น MD ของบริษัทเลยสั่งว่า งั้นให้ใช้ password เดียวกับ email แล้วดูว่าจะบอก password กันอีกหรือเปล่า IT department เลยขอให้ผมซึ่งเป็นที่ปรึกษาของบริษัทอยู่ช่วยทำให้

มาดู Mail Server ที่ติดตั้งไว้เป็น Linux SIS 5.0 ก็เลยทำอะไรง่ายขึ้นมานิดนึง เพราะว่า email ของ Linux SIS ใช้ OpenLDAP เลยคิดว่าน่าจะใช้ LDAP authentication client ดีกว่า ส่วน Application/File Server เป็น Ubuntu 6.10 (Edgy)

ลองหาว่ามีใครทำแบบนี้แล้วบ้างก็เจอที่นี่ เลยเอามาดัดแปลงวิธีการ

ก่อนอื่นติดตั้ง libpam-ldap และ libnss-ldap
$ sudo aptitude install libpam-ldap libnss-ldap
หลังจากนั้นจะเข้าสู่การ configure libnss-ldap โดยมีขั้นตอนดังนี้

  • LDAP Server Host ใส่ IP address ของ LDAP Server ในที่นี้ก็คือ IP ของ Linux SIS ซึ่งเป็น LDAP Server ที่จะใช้
  • distinguished name of search base ใส่ dc=sis,dc=com ซึ่งเป็น default dn ที่ Linux SIS ใช้
  • LDAP version เลือก 3 ตาม Linux SIS
  • LDAP account for root ใส่ uid=root,ou=People,dc=sis,dc=com
  • LDAP root account password ใส่ password ของ Linux SIS root
  • จากนั้นจะได้รับคำเตือนว่า nsswitch.conf ไม่ได้ถูกแก้ เราจะกลับมาจัดการทีหลัง

เสร็จแล้วก็จะต่อด้วยการ configure libpam-ldap

  • ถามว่า Make local root Database admin ตอบ Yes
  • Database requires logging in ตอบ No
  • Root login account ใส่ uid=root,ou=People,dc=sis,dc=com
  • Root login password ใส่ password ของ Linux SIS root

ลองทดสอบว่าเราใส่ค่าถูกต้องหรือไม่ โดยใช้คำสั่ง getent passwd <Linux SIS username> ถ้าถูกต้องจะแสดงผลลักษณะนี้
admin:x:499:499:admin:/home/admin:/bin/bash

อย่าใช้ username ที่มีอยู่บนเครื่องที่กำลังแก้ไขเพราะถ้าค่าที่ป้อนผิด ข้อมูลก็จะออกมาเหมือนกัน หลังจากนั้นตรวจสอบว่า /etc/libnss-ldap.conf และ /etc/pam_ldap.conf มีบรรทัดเหล่านี้ตามที่กำหนดไว้หรือไม่ เพราะอาจมีปัญหาถึงกับ login ไม่ได้
host <ldap server ip address>
base dc=sis,dc=com
ldap_version 3
rootbinddn uid=root,ou=People,dc=sis,dc=com

ตรวจสอบว่า /etc/libnss-ldap.secret และ /etc/pam_ldap.secret เก็บ password ของ Linux SIS root หรือเปล่า

แก้ไข /etc/pam.d/common-account
account sufficient pam_ldap.so # ก่อน pam_unix.so
account required pam_unix.so

แก้ไข /etc/pam.d/common-auth
auth sufficient pam_ldap.so # ก่อน pam_unix.so
auth required pam_unix.so nullok_secure

แก้ไข /etc/pam.d/common-password
password sufficient pam_ldap.so # ก่อน pam_unix.so
password required pam_unix.so nullok obscure min=4 max=8 md5

แก้ไข /etc/nsswitch.conf เปลี่ยน compat ไปเป็น files ldap ในทุกบรรทัด
passwd: files ldap
group: files ldap
shadow: files ldap

เ พื่อให้ user สามารถ login บน server ที่ใช้ LDAP Authentication client ต้องสร้าง home directory ให้ตรงกับที่กำหนดที่ Linux SIS ซึ่งก็คือ /home/<ldap user> แล้วเปลี่ยนเจ้าของและสิทธิตามสมควร
$sudo mkdir /home/<ldap user>
$sudo chown <ldap user>:<ldap group> /home/<ldap user>

เสร็จแล้ว!!!

ขอคุณค้าบ

ขอคุณค้าบบบ

--

Elen síla lumenn' omentielvo
ดวงดาวจรัสแสง ยามเราพบกัน

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <i> <center> <span> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <br> <dt> <dd> <object> <embed> <hr> <img> <blockquote> <b> <u> <del> <div> <p> <table> <tr> <td> <font>

More information about formatting options