<?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>เพื่อชีวิตที่ผ่อนคลายของคนใช้ลีนุกซ์</description>
	<lastBuildDate>Sat, 12 May 2012 10:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>คอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP</title>
		<link>http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap</link>
		<comments>http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap#comments</comments>
		<pubDate>Sun, 18 Mar 2012 07:12:32 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Web Server]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1712</guid>
		<description><![CDATA[จากบทความ คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ เป็นการตรวจสอบ user จาก Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง proxy server เอง แต่ถ้าบริษัทหรือองค์กรของเรามีการเก็บ user, password อยู่บนเซิร์ฟเวอร์เครื่องอื่น เช่นเก็บรวมเป็นศูนย์กลางบน LDAP Server เราก็สามารถคอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP Server ได้ วิธีการคือ แก้ไขคอนฟิกในส่วนของ auth_param basic program เปลี่ยนไปใช้ไฟล์ basic_ldap_auth สมมติว่าค่าคอนฟิกต่างๆ ของ LDAP Server มีดังนี้ ออปชั่น &#8216;-v&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>จากบทความ <a href="http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password">คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ</a></p>
<p>เป็นการตรวจสอบ user จาก Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง proxy server เอง</p>
<p>แต่ถ้าบริษัทหรือองค์กรของเรามีการเก็บ user, password อยู่บนเซิร์ฟเวอร์เครื่องอื่น เช่นเก็บรวมเป็นศูนย์กลางบน LDAP Server เราก็สามารถคอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP Server ได้</p>
<p><span id="more-1712"></span></p>
<p>วิธีการคือ แก้ไขคอนฟิกในส่วนของ auth_param basic program เปลี่ยนไปใช้ไฟล์ basic_ldap_auth</p>
<p>สมมติว่าค่าคอนฟิกต่างๆ ของ LDAP Server มีดังนี้</p>
<ul>
<li>ออปชั่น &#8216;-v&#8217; ระบุเวอร์ชั่นของ LDAP ที่ใช้ = 3</li>
<li>ออปชั่น &#8216;-b&#8217; ระบุ Base DN สำหรับการค้นหา = &#8220;dc=example,dc=com&#8221;</li>
<li>ออปชั่น &#8216;-f&#8217; ระบุเงื่อนไขการค้นหา uid=% คือให้ค้นหาการ username (บน LDAP Server ก็ต้องเก็บโดยใช้ชื่อฟิลด์ uid ด้วย)</li>
<li>ออปชั่น &#8216;-h&#8217; ระบุ IP Address = 192.168.1.10</li>
</ul>
<p>แต่ถ้า LDAP Server ที่คุณใช้ ต้องมีการระบุชื่อ DN และ password ที่ใช้ bind ด้วย ก็ต้องระบุ 2 ออปชั่นนี้เพิ่มเติม</p>
<ul>
<li>ออปชั่น &#8216;-D&#8217; ระบุชื่อ DN สำหรับการ bind เข้า LDAP</li>
<li>ออปชั่น &#8216;-w&#8217; ระบุ password ที่ใช้ bind เข้า LDAP</li>
</ul>
<p>ตัวอย่างการแก้ไขคอนฟิก</p>
<pre>[root@fc16-64a ~]# <strong>cat /etc/squid/squid.conf</strong>
....
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
auth_param basic children 5
auth_param basic realm Proxy Authentication
auth_param basic credentialsttl 12 hours
<span style="color: #0000ff;">auth_param basic program /usr/lib64/squid/basic_ldap_auth -v 3 -b "dc=example,dc=com" -f uid=%s -h 192.168.1.10</span></pre>
<pre>acl <span style="color: #0000ff;">user_ldap_auth</span> proxy_auth REQUIRED
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet <span style="color: #0000ff;">user_ldap_auth</span>
...</pre>
<p>ใช้คำสั่ง service หรือ systemctl เพื่อ start หรือ reload เซอร์วิส squid</p>
<pre>[root@fc16-64a ~]# <strong>systemctl reload squid.service</strong></pre>
<p>เสร็จแล้วลองทดสอบจาก Browser</p>
<p><strong>หมายเหตุ</strong> หลังจากทดสอบเรียบร้อยใช้งานได้แล้ว เพื่อความปลอดภัยของเซิร์ฟเวอร์ หากคุณเปลี่ยนจาก basic_pam_auth มาเป็น basic_ldap_auth แล้ว ให้ยกเลิก setuid root ของไฟล์ basic_pam_auth ด้วย ใช้คำสั่ง chmod ดังนี้</p>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #ff0000;">s</span>r-x---. 1 root squid 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<pre>[root@fc16-64a ~]# <strong>chmod u-s /usr/lib64/squid/basic_pam_auth</strong></pre>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #0000ff;">x</span>r-x---. 1 root squid 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<p>&nbsp;</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password">คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ</a></li>
<li><a href="http://spalinux.com/2010/07/install_openldap_server_on_fedora_13">ติดตั้ง OpenLDAP Server บน Fedora 13</a></li>
<li><a href="http://www.squid-cache.org/Versions/v3/3.2/manuals/basic_ldap_auth.html" target="_blank">squid: basic_ldap_auth</a></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ</title>
		<link>http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password</link>
		<comments>http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password#comments</comments>
		<pubDate>Fri, 16 Mar 2012 18:18:54 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[pam]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1701</guid>
		<description><![CDATA[บทความนี้อธิบายวิธีการคอนฟิก Squid Proxy Server เพื่อให้ผู้ใช้งานต้องใส่ user, password ก่อนถึงจะใช้งานอินเตอร์เน็ตได้ โดยจะตรวจสอบ user, password กับ Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง Proxy Server เอง ทดสอบบน Fedora 16 ติดตั้ง squid-3.2.0.12-1 ติดตั้งไฟล์ rpm จากแผ่นดีวีดีติดตั้ง [root@fc16-64a ~]# mount /dev/cdrom /mnt/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only [root@fc16-64a ~]# cd /mnt/cdrom/Packages/ [root@fc16-64a Packages]# rpm -i squid-3.2.0.12-1.fc16.x86_64.rpm มีหลายวิธีที่คอนฟิกให้ถาม [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้อธิบายวิธีการคอนฟิก Squid Proxy Server เพื่อให้ผู้ใช้งานต้องใส่ user, password ก่อนถึงจะใช้งานอินเตอร์เน็ตได้</p>
<p>โดยจะตรวจสอบ user, password กับ Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง Proxy Server เอง</p>
<p><span id="more-1701"></span></p>
<p>ทดสอบบน Fedora 16 ติดตั้ง squid-3.2.0.12-1</p>
<p>ติดตั้งไฟล์ rpm จากแผ่นดีวีดีติดตั้ง</p>
<pre>[root@fc16-64a ~]# <strong>mount /dev/cdrom /mnt/cdrom</strong>
mount: block device /dev/sr0 is write-protected, mounting read-only</pre>
<pre>[root@fc16-64a ~]# <strong>cd /mnt/cdrom/Packages/</strong>
[root@fc16-64a Packages]# <strong>rpm -i squid-3.2.0.12-1.fc16.x86_64.rpm</strong></pre>
<p>มีหลายวิธีที่คอนฟิกให้ถาม user, password ก่อนใช้ proxy ได้ วิธีหนึ่งคือเพิ่มคอนฟิกออปชั่น auth_param basic มี 3 ขั้นตอนดังนี้</p>
<ol>
<li>ตั้งค่าคอนฟิกของ auth_param basic มีอยู่หลายค่า บรรทัดสำคัญคือ program ในที่นี้จะเลือกเป็น basic_pam_auth เพื่อให้ตรวจสอบกับ Linux PAM</li>
<li>สร้าง acl เป็นชนิด proxy_auth ในตัวอย่างนี้ ตั้งชื่อ acl เป็น user_pam_auth</li>
<li>สุดท้ายนำ acl ที่สร้างขึ้นไปผูกเงื่อนไขใน http_access เช่นในที่นี้ ยังคงอนุญาตให้เครื่องที่อยู่ใน localnet ใช้ proxy ได้ แต่ต้องใส่ user, password ก่อน</li>
</ol>
<p>ตัวอย่างแก้ไขไฟล์ /etc/squid/squid.conf (แสดงเฉพาะส่วนที่แก้ไขจากดีฟอลต์คอนฟิกเท่านั้น)</p>
<pre>[root@fc16-64a ~]# <strong>cat /etc/squid/squid.conf</strong>
....
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
<span style="color: #0000ff;"><strong>auth_param basic children 5</strong></span>
<span style="color: #0000ff;"><strong>auth_param basic realm Proxy Authentication</strong></span>
<span style="color: #0000ff;"><strong>auth_param basic credentialsttl 12 hours</strong></span>
<span style="color: #0000ff;"><strong>auth_param basic program /usr/lib64/squid/basic_pam_auth</strong></span></pre>
<pre><span style="color: #0000ff;"><strong>acl user_pam_auth proxy_auth REQUIRED</strong></span></pre>
<pre># Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet <strong><span style="color: #0000ff;">user_pam_auth</span></strong>
...</pre>
<p>&nbsp;</p>
<p>ใช้คำสั่ง service หรือ systemctl เพื่อ start หรือ reload เซอร์วิส squid</p>
<pre>[root@fc16-64a ~]# <strong>systemctl reload squid.service</strong></pre>
<p>ใช้คำสั่ง useradd เพิ่ม user สำหรับทดสอบ</p>
<pre>[root@fc16-64a ~]# <strong>useradd -g users user1</strong>
[root@fc16-64a ~]# <strong>passwd user1</strong>
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.</pre>
<pre></pre>
<h4>ทดสอบจาก Browser</h4>
<p>คอนฟิก Browser ของเครื่องผู้ใช้ ให้ชี้มาที่ proxy แล้วลองเข้าเว็บดู จะมีหน้าจอให้ใส่ user, password ลองใส่ user ที่เพิ่งสร้างขึ้น</p>
<p><a href="http://spalinux.com/wp-content/uploads/2012/03/p01-user-password.png"><img class="alignnone size-full wp-image-1702" title="p01-user-password" src="http://spalinux.com/wp-content/uploads/2012/03/p01-user-password.png" alt="" width="620" height="242" /></a></p>
<p>&nbsp;</p>
<p>แม้จะพยายามใส่ user, password อย่างไร ก็ไม่สำเร็จ</p>
<p><a href="http://spalinux.com/wp-content/uploads/2012/03/p02-cache-denied.png"><img class="alignnone size-full wp-image-1703" title="p02-cache-denied" src="http://spalinux.com/wp-content/uploads/2012/03/p02-cache-denied.png" alt="" width="786" height="299" /></a></p>
<p>&nbsp;</p>
<p>ที่เป็นเช่นนี้เนื่องจาก basic_pam_auth ไ่ม่สามารถอ่านไฟล์ /etc/shadow ได้ จำเป็นต้องแก้ไขไฟล์นี้ให้เป็น setuid root</p>
<p>ใช้คำสั่ง chmod เพื่อแก้ไขไฟล์ให้เป็น setuid root</p>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rwxr-xr-x. 1 root root 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<pre>[root@fc16-64a ~]# <strong>chmod u+s /usr/lib64/squid/basic_pam_auth</strong></pre>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #ff0000;">s</span>r-xr-x. 1 root root 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<p>&nbsp;</p>
<p>แต่การใช้ setuid root แบบนี้ ค่อนข้างอันตราย user ทั่วไป บนเครื่องเซิร์ฟเวอร์ สามารถรันโปรแกรมนี้แล้วตรวจสอบไฟล์ /etc/shadow ได้</p>
<p>วิธีที่จะพอป้องกันได้ คือให้เฉพาะ squid รันไฟล์นี้ได้เท่านั่้น ตัวอย่างเช่น</p>
<pre>[root@fc16-64a ~]# <strong>chmod 750 /usr/lib64/squid/basic_pam_auth</strong>
[root@fc16-64a ~]# <strong>chgrp squid /usr/lib64/squid/basic_pam_auth</strong>
[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rwxr-x<span style="color: #0000ff;">---</span>. 1 root <span style="color: #0000ff;">squid</span> 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<pre>[root@fc16-64a ~]# <strong>chmod u+s /usr/lib64/squid/basic_pam_auth</strong>
[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #ff0000;">s</span>r-x---. 1 root squid 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<p>รีโหลดเซอร์วิสหลังแก้ไข</p>
<pre>[root@fc16-64a ~]# <strong>systemctl reload squid.service</strong></pre>
<p>ลองใส่ user, password อีกครั้ง บน browser น่าจะใช้งานได้แล้ว</p>
<p>&nbsp;</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.squid-cache.org/Versions/v3/3.2/manuals/basic_pam_auth.html" target="_blank">squid: basic_pam_auth</a></li>
<li><a href="http://spalinux.com/2008/05/configure_squid_proxy_server" target="_blank">คอนฟิก Squid Proxy Server</a></li>
<li><a title="View Details: คอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP" href="http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap" rel="bookmark">คอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP</a></li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

