<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaLinux.com &#187; Authentication</title>
	<atom:link href="http://spalinux.com/tag/authentication/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Sat, 21 Jan 2012 16:07:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>คอนฟิกให้ authenticate จาก Fedora Directory Server</title>
		<link>http://spalinux.com/2008/07/authenticate_user_on_fedora_directory_server</link>
		<comments>http://spalinux.com/2008/07/authenticate_user_on_fedora_directory_server#comments</comments>
		<pubDate>Fri, 04 Jul 2008 14:06:19 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Directory Server]]></category>
		<category><![CDATA[ldap]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=49</guid>
		<description><![CDATA[หลังจากที่เราติดตั้งและคอนฟิก Fedora Directory Server เรียบร้อยแล้ว ในบทความนี้จะอธิบายถึงการเก็บ UNIX User Account และ Group เข้าไปใน LDAP เพื่อที่จะใช้รองรับการ authentication จากโปรแกรมต่างได้ เช่น สำหรับการ login, secure shell และอื่นๆ โดยดีฟอลต์เมื่อติดตั้ง Fedora Directory Server ตัวโปรแกรมจะสร้างข้อมูลพื้นฐานขึ้นมาจำนวนหนึ่ง ซึ่งประกอบด้วย Base DN – ซึ่งจะเป็นชื่อพื้นฐานโดเมนที่เราใช้ตอนติดตั้ง ในบทความนี้จะคอนฟิกอยู่ในโดเมน (BASE) เป็น dc=your-domain, dc=com ที่รันอยู่บนเครื่องที่ชื่อ “server” ou=Users – มีไว้สำหรับเก็บข้อมูลของผู้ใช้งาน ซึ่งเราจะไว้เก็บ UNIX User Account จากไฟล์ /etc/passwd ou=Groups – จะเป็นส่วนที่เก็บข้อมูลกลุ่มของผู้ใช้งาน (Groups) ซึ่งเราจะไว้เก็บ UNIX Group [...]]]></description>
			<content:encoded><![CDATA[<p>หลังจากที่เราติดตั้งและคอนฟิก Fedora Directory Server เรียบร้อยแล้ว ในบทความนี้จะอธิบายถึงการเก็บ UNIX User Account และ Group เข้าไปใน LDAP  เพื่อที่จะใช้รองรับการ authentication จากโปรแกรมต่างได้ เช่น สำหรับการ login, secure shell และอื่นๆ</p>
<p><span id="more-49"></span></p>
<p>โดยดีฟอลต์เมื่อติดตั้ง Fedora Directory Server ตัวโปรแกรมจะสร้างข้อมูลพื้นฐานขึ้นมาจำนวนหนึ่ง ซึ่งประกอบด้วย</p>
<ul>
<li><strong>Base DN</strong> – ซึ่งจะเป็นชื่อพื้นฐานโดเมนที่เราใช้ตอนติดตั้ง ในบทความนี้จะคอนฟิกอยู่ในโดเมน (BASE) เป็น dc=your-domain, dc=com ที่รันอยู่บนเครื่องที่ชื่อ “server”</li>
<li><strong>ou=Users</strong> – มีไว้สำหรับเก็บข้อมูลของผู้ใช้งาน ซึ่งเราจะไว้เก็บ UNIX User Account จากไฟล์ /etc/passwd</li>
<li><strong>ou=Groups</strong> – จะเป็นส่วนที่เก็บข้อมูลกลุ่มของผู้ใช้งาน (Groups) ซึ่งเราจะไว้เก็บ UNIX Group  จากไฟล์ /etc/group</li>
</ul>
<p>ในการที่จะ authenticate รหัสผู้ใช้งานจาก LDAP ได้นั้น เราจะต้องนำข้อมูลของผู้ใช้งานจากไฟล์ /etc/passwd, /etc/group ไปเก็บไว้ใน LDAP โดยจะมีวิธีการอยู่หลายวิธี แต่ในที่นี้จะแนะนำวิธีการสร้างไฟล์ ldif ขึ้นมา แล้วค่อย import เข้าไปใน LDAP โดยที่ Directory Server กำลังทำงานอยู่</p>
<p><strong>สร้างไฟล์ passwd.ldif</strong><br />
เริ่มต้นสร้างไฟล์ passwd.ldif ซึ่งจะเก็บ user account และรายละเอียดของ user นั้นๆ อยู่ ซึ่งจากตัวอย่างด้านล้าง จะเป็นข้อมูลของผู้ใช้งานที่ใช้ login เป็น user01 (uid: user01)</p>
<pre>dn: uid=user01,ou=People,dc=your-domain,dc=com
uid: user01
cn: user01
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}*
shadowLastChange: 14050
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 601
gidNumber: 600
homeDirectory: /home/user01
gecos: user01</pre>
<p>ถ้าต้องการสร้างผู้ใช้หลายๆ คน ก็เพิ่มข้อมูลต่อท้ายลงไปในไฟล์นี้โดยให้เว้นไว้บรรทัดว่างไว้หนึ่งบรรทัด ระหว่างข้อมูลแต่ละ user</p>
<p><strong>สร้างไฟล์ group.ldif</strong><br />
ขั้นต่อไปสร้างไฟล์ group.ldif ซึ่งจะเก็บ UNIX Group และรายละเอียด ซึ่งจากตัวอย่างด้านล้าง จะเป็นข้อมูลของกลุ่มผู้ใช้งานที่ชื่อ ldapuser</p>
<pre>dn: cn=ldapusers,ou=Groups,dc=your-domain,dc=com
objectClass: posixGroup
objectClass: top
cn: ldapusers
userPassword: {crypt}x
gidNumber: 600</pre>
<p><strong>Import ข้อมูลจากไฟล์ ldif เข้าไปใน LDAP</strong><br />
เมื่อได้ไฟล์ ldif แล้ว ต้องใช้คำสั่ง ldif2ldap เพื่อนำข้อมูลจากไฟล์เข้าไปเก็บไว้ใน LDAP โดยก่อนที่จะรันคำสั่งนี้ได้ Directory Server ต้องรันทำงานอยู่แล้ว</p>
<p>เวลาที่รันคำสั่ง ldif2ldap จำเป็นต้องระบุ “cn=Directory Manager” และรหัสผ่านลงไปด้วย โดยรหัสผ่านนี้คือรหัสที่ใส่ตอนใช้คำสั่ง setup-ds-admin.pl ตอนที่คอนฟิก Directory Server ตั้งแต่ตอนแรกที่ติดตั้ง</p>
<p>ตัวอย่างการรันคำสั่ง ldif2ldap เพื่อนำข้อมูลจากไฟล์เข้าไปใน LDAP</p>
<pre>[root@server ~]#<strong> /usr/lib/dirsrv/slapd-server/ldif2ldap "cn=Directory Manager" &lt;password&gt; passwd.ldif</strong>
adding new entry uid=user01,ou=People,dc=your-domain,dc=com</pre>
<pre>[root@server ~]# <strong>/usr/lib/dirsrv/slapd-server/ldif2ldap "cn=Directory Manager" &lt;password&gt; group.ldif
</strong>adding new entry cn=ldapusers,ou=Groups,dc=your-domain,dc=com</pre>
<p>หมายเหตุ<br />
- ในที่นี้จะรันอยู่บนเครื่องที่ชื่อ server ดังนั้น path ที่ใช้จะเป็น /usr/lib/dirsrv/slapd-server/ ซึ่งถ้าคุณรันคำสั่งนี้บนชื่อเครื่องอื่นๆ ให้เปลี่ยนตรงคำว่า server<br />
- ให้สังเกตผลลัพธ์จากการรันคำสั่ง ldif2ldap ด้วย ว่าสำเร็จหรือไม่ ถ้าไม่สำเร็จ ให้แก้ไข ไฟล์และรันใหม่อีกครั้ง</p>
<p><strong>เปลี่ยนคอนฟิกของเครื่องให้อ่านข้อมูล User Account และ Group จาก LDAP ด้วย</strong><br />
โดยดีฟอลต์ของ Linux ข้อมูล User Account และ Group จะถูกอ่านจากไฟล์ /etc/passwd และ /etc/group ตามลำดับ ถ้าเราต้องการให้มาอ่านข้อมูลจาก LDAP ด้วย ให้ใช้คำสั่ง authconfig-tui เพื่อแก้คอนฟิก</p>
<pre>
[root@server ~]# <strong>authconfig-tui
</strong>┌────────────────┤ Authentication Configuration ├─────────────────┐
│                                                                 │
│  User Information        Authentication                         │
│  [*] Cache Information   [ ] Use MD5 Passwords                  │
│  [ ] Use Hesiod          [*] Use Shadow Passwords               │
│  <strong>[*] Use LDAP</strong>            <strong>[*] Use LDAP Authentication</strong>            │
│  [ ] Use NIS             [ ] Use Kerberos                       │
│  [ ] Use Winbind         [ ] Use SMB Authentication             │
│                          [ ] Use Winbind Authentication         │
│                          [*] Local authorization is sufficient  │
│                                                                 │
│            ┌────────┐                      ┌──────┐             │
│            │ Cancel │                      │ Next │             │
│            └────────┘                      └──────┘             │
│                                                                 │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘</pre>
<p>คลิ้กเลือก [*] Use LDAP และ [*] Use LDAP Authentication แล้วกดปุ่ม Next</p>
<pre>┌─────────────────┤ LDAP Settings ├─────────────────┐
│                                                   │
│          [ ] Use TLS                              │
│  Server: <strong>ldap://localhost/</strong>_______________________ │
│ Base DN: <strong>dc=your-domain,dc=com</strong>___________________ │
│                                                   │
│         ┌──────┐                  ┌────┐          │
│         │ Back │                  │ Ok │          │
│         └──────┘                  └────┘          │
│                                                   │
│                                                   │
└───────────────────────────────────────────────────┘</pre>
<p>ใส่คอนฟิกของ Server เป็น ldap://localhost และ ใส่ Base DN: เป็น dn=your-domain, dc=com แล้วกดปุ่ม Ok</p>
<p>คำสั่ง authconfig-tui จะไปแก้ไฟล์ /etc/ldap.conf และไฟล์ต่างๆ ใน /etc/pam.d/ ซึ่งหลังจากแก้ไขแล้ว ต่อไปเวลาตรวจสอบชื่อหรือรหัสผู้ใช้งาน ระบบจะตรวจสอบจากไฟล์ /etc/passwd และ /etc/group ก่อน ถ้าหาไม่พบถึงจะไปค้นหาใน LDAP อีกที</p>
<p><strong>ทดสอบการใช้งาน</strong><br />
สามารถใช้คำสั่ง id เพื่อตรวจสอบ User Account จาก LDAP ได้ โดยผลลัพธ์ที่ได้จะมี uid, group ของผู้ใช้งานนั้นๆ</p>
<p>ตัวอย่างการใช้คำสั่ง id เพื่อตรวจสอบ User จาก LDAP</p>
<pre>[root@server ~]# <strong>id user01
</strong>uid=601(user01) gid=600(ldapusers) groups=600(ldapusers)</pre>
<p>ถ้าต้องการเปลี่ยนแปลงข้อมูล เช่น password หรือต้องการลบ แนะนำให้ใช้ Management Console ได้ จากการรันคำสั่ง fedora-idm-console ใน X Window</p>
<p><strong>ข้อมูลอ้างอิง</strong></p>
<ul>
<li><a href="http://spalinux.com/2008/06/basic_install_configure_fedora_directory_server">ติดตั้งและคอนฟิก Fedora Directory Server เบื้องต้น</a></li>
<li><a href="http://directory.fedoraproject.org/wiki/Howto:PAM" target="_blank">PAM Configuration for LDAP Client Systems </a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/07/authenticate_user_on_fedora_directory_server/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

