<?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/category/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>จำกัดจำนวน login พร้อมกันของผู้ใช้เดียวกัน</title>
		<link>http://spalinux.com/2011/05/limit_maximum_number_of_logins_for_user</link>
		<comments>http://spalinux.com/2011/05/limit_maximum_number_of_logins_for_user#comments</comments>
		<pubDate>Sun, 08 May 2011 07:13:52 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Linux Shell]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1325</guid>
		<description><![CDATA[การจำกัด (limit) จำนวนการ login พร้อมกันโดยใช้ชื่อผู้ใช้เดียวกัน สามารถคอนฟิกด้วยออปชั่น &#8220;maxlogins&#8221; ในไฟล์ /etc/security/limits.conf คำอธิบายออปชั่น &#8220;maxlogins&#8221; คือ max number of logins for this user คอนฟิกได้สองแบบคือ จำกัดเป็นรายคน เช่น ชื่อผู้ใช้ user1 สามารถ login ได้สูงสุดพร้อมกันได้แค่ 2 sessions แต่ถ้าต้องการจำกัดผู้ใช้ที่อยู่ในกลุ่ม (group) ให้เติมเครื่องหมาย @ ข้างหน้าชื่อกลุ่ม ตัวอย่างคอนฟิก จำกัดผู้ใช้ user1 ให้ login พร้อมกันได้แค่ 2 sessions เท่านั้น [root@server ~]# cat /etc/security/limits.conf user1           -       maxlogins       2 หลังแก้ไขไฟล์แล้ว คอนฟิกใหม่มีผลต่อการ login ครั้งต่อไปเลย [...]]]></description>
			<content:encoded><![CDATA[<p>การจำกัด (limit) จำนวนการ login พร้อมกันโดยใช้ชื่อผู้ใช้เดียวกัน สามารถคอนฟิกด้วยออปชั่น &#8220;maxlogins&#8221; ในไฟล์ /etc/security/limits.conf</p>
<p>คำอธิบายออปชั่น &#8220;maxlogins&#8221; คือ max number of logins for this user</p>
<p><span id="more-1325"></span></p>
<p>คอนฟิกได้สองแบบคือ จำกัดเป็นรายคน เช่น ชื่อผู้ใช้ user1 สามารถ login ได้สูงสุดพร้อมกันได้แค่ 2 sessions แต่ถ้าต้องการจำกัดผู้ใช้ที่อยู่ในกลุ่ม (group) ให้เติมเครื่องหมาย @ ข้างหน้าชื่อกลุ่ม</p>
<p>ตัวอย่างคอนฟิก จำกัดผู้ใช้ user1 ให้ login พร้อมกันได้แค่ 2 sessions เท่านั้น</p>
<pre>[root@server ~]# <strong>cat /etc/security/limits.conf
</strong>user1           -       maxlogins       2</pre>
<p>หลังแก้ไขไฟล์แล้ว คอนฟิกใหม่มีผลต่อการ login ครั้งต่อไปเลย ไม่จำเป็นต้องรีสตาร์ตโปรแกรม หรือเซอร์วิสใด</p>
<p>ตัวอย่างข้อความในไฟล์ /var/log/secure ที่เกิดขึ้น ระหว่างการทดสอบ login</p>
<p>login ด้วย user1 ครั้งแรก ได้</p>
<pre>Jul  8 13:21:19 server sshd[2375]: Accepted password for user1 from 192.168.1.12 port 4310 ssh2
Jul  8 13:21:19 server sshd[2375]: pam_unix(sshd:session): session opened for user user1 by (uid=0)</pre>
<p>login ด้วย user1 ครั้งที่ 2 ก็ได้</p>
<pre>Jul  8 13:21:39 server sshd[2400]: Accepted password for user1 from 192.168.1.12 port 4311 ssh2
Jul  8 13:21:39 server sshd[2400]: pam_unix(sshd:session): session opened for user user1 by (uid=0)</pre>
<p>ใช้คำสั่ง w เพื่อดูผู้ใช้ที่ login อยู่</p>
<pre>[user1@server ~]$ <strong>w</strong>
 13:21:49 up 14 min,  3 users,  load average: 0.07, 0.19, 0.25
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
admin    pts/0    192.168.1.12         13:19   35.00s  0.72s  0.18s sshd: admin [priv]
user1    pts/1    192.168.1.12         13:21   30.00s  0.20s  0.20s -bash
user1    pts/2    192.168.1.12         13:21    0.00s  0.25s  0.04s w</pre>
<p>login ด้วย user1 ครั้งที่ 3 จะไม่ได้แล้ว</p>
<pre>Jul  8 13:22:00 server sshd[2426]: Accepted password for user1 from 192.168.1.12 port 4312 ssh2
Jul  8 13:22:00 server sshd[2426]: <span style="color: #ff0000;"><strong>pam_limits(sshd:session): Too many logins (max 2) for user1
</strong></span>Jul  8 13:22:00 server sshd[2426]: pam_unix(sshd:session): session opened for user user1 by (uid=0)
Jul  8 13:22:00 server sshd[2426]: error: PAM: pam_open_session(): Permission denied</pre>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/05/limit_maximum_number_of_logins_for_user/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ล็อกอินผิดมากเกิน แบนซะด้วย fail2ban</title>
		<link>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban</link>
		<comments>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban#comments</comments>
		<pubDate>Sat, 07 May 2011 09:01:08 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[fail2ban]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1316</guid>
		<description><![CDATA[หากเซิร์ฟเวอร์ของคุณตั้งอยู่บนอินเตอร์เน็ต เพื่อให้บริการเว็บไซต์หรืออื่นๆ และคุณจำเป็นต้องเปิด SSH เพื่อสามารถ login เข้าไปตรวจสอบสถานะของเครื่องได้ คุณต้องเคยเจอปัญหานี้แน่นอน คือมีการพยายามเจาะระบบด้วยการ ssh เข้ามา ด้วย user, password ต่างๆ ที่คาดว่าจะมีในเครื่อง ตัวอย่างไฟล์ /var/log/secure แสดงถึงการพยายาม ssh แต่ไม่สำเร็จ May  2 16:39:27 server sshd[8309]: Invalid user john from x.x.x.x May  2 16:39:27 server sshd[8310]: input_userauth_request: invalid user john May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): check pass; user unknown May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): [...]]]></description>
			<content:encoded><![CDATA[<p>หากเซิร์ฟเวอร์ของคุณตั้งอยู่บนอินเตอร์เน็ต เพื่อให้บริการเว็บไซต์หรืออื่นๆ และคุณจำเป็นต้องเปิด SSH เพื่อสามารถ login เข้าไปตรวจสอบสถานะของเครื่องได้</p>
<p>คุณต้องเคยเจอปัญหานี้แน่นอน คือมีการพยายามเจาะระบบด้วยการ ssh เข้ามา ด้วย user, password ต่างๆ ที่คาดว่าจะมีในเครื่อง</p>
<p><span id="more-1316"></span></p>
<p>ตัวอย่างไฟล์ /var/log/secure แสดงถึงการพยายาม ssh แต่ไม่สำเร็จ</p>
<pre>May  2 16:39:27 server sshd[8309]: Invalid user john from x.x.x.x
May  2 16:39:27 server sshd[8310]: input_userauth_request: invalid user john
May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): check pass; user unknown
May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=x.x.x.x
May  2 16:39:27 server sshd[8309]: pam_succeed_if(sshd:auth): error retrieving information about user john
May  2 16:39:29 server sshd[8309]: Failed password for invalid user john from x.x.x.x port 3291 ssh2
May  2 16:39:29 server sshd[8310]: Received disconnect from x.x.x.x: 11: Bye Bye</pre>
<pre> </pre>
<p>การป้องกัน หรือคำแนะนำอย่างแรก ที่พึงกระทำคือ ตั้ง user, password ให้ยากต่อการคาดเดา แต่เท่านั้นอาจไม่เพียงพอ</p>
<p>บทความนี้ขอเสนอวิธีการป้องกันด้วย fail2ban ซึ่งจะช่วยแบน ip ที่พยายาม login แต่ไม่สำเร็จได้</p>
<p>หลักการทำงานคร่าวๆ คือ โปรแกรม fail2ban จะคอยตรวจสอบไฟล์ที่ตั้งไว้ โดยค้นหาคำหรือประโยคที่เกิดขึ้นในไฟล์ เมื่อมีการ failed attempts เกิดขึ้นถึงจำนวนครั้งที่กำหนด fail2ban จะทำการบางอย่างที่ตั้งไว้ เช่น รันคำสั่ง iptables เพื่อ DROP packets ได้</p>
<h4>ติดตั้งไฟล์ rpm</h4>
<p>ในที่นี้ทดสอบบน Fedora 14 ต้องติดตั้งไฟล์ rpm เพิ่มเติมดังนี้</p>
<pre>[root@fc14-x64 ~]# <strong>rpm -ivh gamin-python-0.1.10-8.fc14.x86_64.rpm
</strong>[root@fc14-x64 ~]# <strong>rpm -ivh shorewall-4.4.11.1-1.fc14.noarch.rpm
</strong>[root@fc14-x64 ~]# <strong>rpm -ivh fail2ban-0.8.4-25.fc14.noarch.rpm</strong></pre>
<p>เพื่อความชัดเจนในการทดสอบ จะรันคำสั่ง service iptables stop เพื่อเคลียร์ rule ของ iptables ทั้งหมดออกก่อน</p>
<pre>[root@fc14-x64 ~]# <strong>service iptables stop
</strong>iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]</pre>
<p>ใช้คำสั่ง iptables เพื่อแสดง rule ที่ใช้งานอยู่</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 46 packets, 3176 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 40 packets, 5272 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>ใช้คำสั่ง service เพื่อสตาร์ต fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>service fail2ban start
</strong>Starting fail2ban:                                         [  OK  ]</pre>
<p>ใช้คำสั่ง ps เพื่อดูโปรเซสของ fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>ps -ef | grep fail2ban
</strong>root      1151     1  0 23:32 ?        00:00:00 /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock -x</pre>
<p>ดูในไฟล์ /var/log/messages แสดงการเริ่มต้นทำงานของ fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages</strong></pre>
<pre>May  6 23:35:32 fc14-x64 fail2ban.server : INFO   Changed logging target to SYSLOG for Fail2ban v0.8.4
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Creating new jail 'ssh-iptables'
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Jail 'ssh-iptables' uses Gamin
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Added logfile = /var/log/secure
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Set maxRetry = 5
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Set findtime = 600
May  6 23:35:32 fc14-x64 fail2ban.actions: INFO   Set banTime = 600
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Jail 'ssh-iptables' started</pre>
<p>ดีฟอลต์คอนฟิกไฟล์ rpm ที่ได้มาจาก Fedora 14 จะตรวจสอบเฉพาะการพยายาม SSH โดยดูในไฟล์ /var/log/secure</p>
<p>fail2ban จะสร้าง rule และ chain ใหม่ขึ้นมา ใน iptables</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 92 packets, 7885 bytes)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>   53  4052 fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22</strong></span></pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 84 packets, 8087 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain <strong><span style="color: #0000ff;">fail2ban-SSH</span> </strong>(1 references)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>   53  4052 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</strong></span></pre>
<p> </p>
<h4>ไฟล์คอนฟิกของ fail2ban</h4>
<p>ไฟล์คอนฟิกของ fail2ban อยู่ใน /etc/fail2ban/</p>
<p>ไฟล์ /etc/fail2ban/jail.conf จะเป็นการกำหนดการทำงานของ fail2ban</p>
<p>คอนฟิกบางส่วนจากไฟล์ jail.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/jail.conf</strong>
...
[DEFAULT]
...
# "bantime" is the number of seconds that a host is banned.
<span style="color: #0000ff;">bantime  = 600</span></pre>
<pre># A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
<span style="color: #0000ff;">findtime  = 600
</span>...
[ssh-iptables]</pre>
<pre>enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           sendmail-whois[name=SSH, dest=root, sender=fail2ban@mail.com]
logpath  = /var/log/secure
maxretry = 5</pre>
<p>คำอธิบายคร่าวๆ จากไฟล์ jail.conf คือ ให้ตรวจสอบ (filter) การ ssh โดยดูในไฟล์ (logpath) /var/log/secure ว่า ถ้ามีการ failed login เกิน (maxretry) ครั้ง ภายในเวลา (findtime) 600 วินาที ให้ทำการ (action) รัน iptables ด้วยออปชั่นในวงเล็บ</p>
<p>สามารถดูรายละเอียด filter ในไฟล์ /etc/fail2ban/filter.d/sshd.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/filter.d/sshd.conf
</strong>...
[Definition]</pre>
<pre>_daemon = sshd
...
failregex = ^%(__prefix_line)s(?:error: PAM: )?Authentication failure for .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)s(?:error: PAM: )?User not known to the underlying authentication module for .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)sFailed (?:password|publickey) for .* from &lt;HOST&gt;(?: port \d*)?(?: ssh\d*)?$
            ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM &lt;HOST&gt;\s*$
            ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)sUser \S+ from &lt;HOST&gt; not allowed because not listed in AllowUsers$
            ^%(__prefix_line)sauthentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=&lt;HOST&gt;(?:\s+user=.*)?\s*$
            ^%(__prefix_line)srefused connect from \S+ \(&lt;HOST&gt;\)\s*$
            ^%(__prefix_line)sAddress &lt;HOST&gt; .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
            ^%(__prefix_line)sUser \S+ from &lt;HOST&gt; not allowed because none of user's groups are listed in AllowGroups$</pre>
<p>คำอธิบายจากไฟล์คอนฟิก filter คือ ให้ตรวจสอบหาคำหรือประโยคที่ระบุไว้ใน failregex (regular expression)</p>
<p>ส่วน action ที่ทำ หลังจาก maxretry ดูได้ในไฟล์  /etc/fail2ban/action.d/iptables.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/action.d/iptables.conf
</strong>...
actionban = iptables -I fail2ban-&lt;name&gt; 1 -s &lt;ip&gt; -j DROP
...
actionunban = iptables -D fail2ban-&lt;name&gt; -s &lt;ip&gt; -j DROP</pre>
<p>คำอธิบาย คือการรันคำสั่ง iptables เพื่อสร้าง rule เพื่อจะ ban &lt;ip&gt; ที่พยายามเข้ามา</p>
<p>และเมื่อเกินเวลา (bantime) 600 วินาที แล้ว ก็รันคำสั่ง iptables เพื่อลบ rule ที่สร้างขึ้น อนุญาตให้ &lt;ip&gt; สามารถเข้ามาได้อีกครั้ง</p>
<h4>ทดสอบการ login fail</h4>
<p><span style="color: #ff0000;"><strong>คำเตือน </strong>การทดลองใช้ fail2ban ให้ลองบนเครื่องที่สามารถ console ได้  เพราะการคอนฟิกหรือลอง login fail จะทำให้คุณไม่สามารถ ssh เข้าเครื่องนั้นได้ ช่วงเวลาหนึ่ง</span></p>
<p>สมมุติให้ลอง ssh login fail ด้วย root จาก 192.168.1.12</p>
<p>ดูไฟล์ /var/log/secure ที่เกิดขึ้นบน server</p>
<pre>[root@fc14-x64 ~]#<strong> tail -f /var/log/secure
</strong>May  6 23:43:47 fc14-x64 unix_chkpwd[1340]: password check failed for user (root)
May  6 23:43:47 fc14-x64 sshd[1338]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root
May  6 23:43:49 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2</pre>
<pre>May  6 23:43:56 fc14-x64 unix_chkpwd[1342]: password check failed for user (root)
May  6 23:43:58 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2</pre>
<pre>May  6 23:44:00 fc14-x64 unix_chkpwd[1343]: password check failed for user (root)
May  6 23:44:01 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2
May  6 23:44:01 fc14-x64 sshd[1339]: Connection closed by 192.168.1.12
May  6 23:44:01 fc14-x64 sshd[1338]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root</pre>
<pre>May  6 23:44:16 fc14-x64 unix_chkpwd[1348]: password check failed for user (root)
May  6 23:44:16 fc14-x64 sshd[1346]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root
May  6 23:44:19 fc14-x64 sshd[1346]: Failed password for root from 192.168.1.12 port 34812 ssh2</pre>
<pre>May  6 23:44:22 fc14-x64 unix_chkpwd[1349]: password check failed for user (root)
May  6 23:44:25 fc14-x64 sshd[1346]: Failed password for root from 192.168.1.12 port 34812 ssh2
May  6 23:44:25 fc14-x64 sshd[1347]: Connection closed by 192.168.1.12
May  6 23:44:25 fc14-x64 sshd[1346]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root</pre>
<p>เมื่อ login fail เกินค่า maxretry ที่ตั้งไว้ ในที่นี้คือ 5 ครั้ง สังเกตในไฟล์ /var/log/messages  โปรแกรม fail2ban จะทำการ action ขึ้นมา เพื่อ ban 192.168.1.12</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages
</strong>May  6 23:44:27 fc14-x64 &lt;28&gt;<span style="color: #0000ff;">fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.12</span></pre>
<p>ใช้คำสั่ง iptables เพื่อตรวจสอบ rule ที่เพิ่มขึ้น</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 61 packets, 10699 bytes)
 pkts bytes target     prot opt in     out     source               destination
  453 37587 fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           <span style="color: #0000ff;"><strong>tcp dpt:22</strong></span></pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 60 packets, 7044 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain fail2ban-SSH (1 references)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>    2   120 DROP       all  --  *      *       192.168.1.12            0.0.0.0/0
</strong></span>  451 37467 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</pre>
<p>สังเกตว่า rule ที่สร้างขึ้น จะ DROP เฉพาะการ ssh (tcp 22) เท่านั้น แปลว่า ip ที่ถูก ban ไป จะไม่สามารถ ssh เข้าเครื่อง server ได้อีก แต่ยังสามารถเปิด web (tcp 80) หรืออื่นๆ ได้ตามปกติ</p>
<p>คอนฟิกในไฟล์ jail.conf เมื่อมีการ ban เกิดขึ้น จะมีการส่ง mail หา root ด้วย</p>
<p>ตัวอย่าง mail ที่ส่งให้ root</p>
<pre>From fail2ban@mail.com  Fri May  6 23:44:28 2011
Return-Path: &lt;fail2ban@mail.com&gt;
Date: Fri, 6 May 2011 23:44:27 +0700
Subject: [Fail2Ban] SSH: banned 192.168.1.12
From: Fail2Ban &lt;fail2ban@mail.com&gt;
To: <a href="mailto:root@fc14-x64.example.com">root@fc14-x64.example.com</a>
Status: R</pre>
<pre>Hi,</pre>
<pre>The IP 192.168.1.12 has just been banned by Fail2Ban after 5 attempts against SSH.
...</pre>
<p>เมื่อเวลาผ่านไป เกินเวลา bantime ในที่นี้ 600 วินาที  โปรแกรม fail2ban ก็จะปลดการ ban ออก ดูได้จากไฟล์ /var/log/messsages</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages
</strong>May  6 23:44:27 fc14-x64 &lt;28&gt;fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.12
May  6 23:54:28 fc14-x64 &lt;28&gt;<span style="color: #0000ff;">fail2ban.actions: WARNING [ssh-iptables] Unban 192.168.1.12</span></pre>
<p>ใช้คำสั่ง iptables เพื่อตรวจสอบ rule ที่ใช้งานอยู่ หลังจาก unban</p>
<pre>[root@fc14-x64 log]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 561 packets, 50572 bytes)
 pkts bytes target     prot opt in     out     source               destination
 1753  141K fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 501 packets, 50410 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain fail2ban-SSH (1 references)
 pkts bytes target     prot opt in     out     source               destination
 1751  141K RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</pre>
<p> </p>
<p>ลองนำไปใช้ดูครับ เพิ่มความปลอดภัยให้เครื่องได้อีกระดับ</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.fail2ban.org/" target="_blank">Fail2ban</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้ง OpenLDAP Server บน Fedora 13</title>
		<link>http://spalinux.com/2010/07/install_openldap_server_on_fedora_13</link>
		<comments>http://spalinux.com/2010/07/install_openldap_server_on_fedora_13#comments</comments>
		<pubDate>Fri, 16 Jul 2010 08:19:45 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Directory Server]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[fedora 13]]></category>
		<category><![CDATA[openldap]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1126</guid>
		<description><![CDATA[การเปลี่ยนแปลงอย่างหนึ่งใน Fedora เวอร์ชั่นหลังๆ คือการเปลี่ยนวิธีการคอนฟิก OpenLDAP ซึ่งจะเป็นรูปแบบใหม่ที่มีมาตั้งแต่ OpenLDAP เวอร์ชั่น 2.3 เป็นต้นมา แต่ทาง Fedora เพิ่งเริ่มนำมาใช้ แบบเก่าไฟล์คอนฟิกหลักจะอยู่ในไฟล์ /etc/openldap/slapd.conf แต่แบบใหม่คอนฟิกจะถูกเก็บแยกเป็นไฟล์ LDIF เป็นโครงสร้างอยู่ในไดเร็คทอรี /etc/openldap/slapd.d/ และเมื่อรันเซอร์วิส ไฟล์เหล่านี้จะถูกอ่านเข้าไปใน LDAP เลย ซึ่งทำให้เราสามารถแก้ไขคอนฟิกเซิร์ฟเวอร์ ได้ เหมือนกับการแก้ไขข้อมูลอื่นๆ ใน LDAP รายละเอียดเพิ่มเติมหาอ่านได้จาก ข้อมูลอ้างอิง Configuring slapd เพื่อความสะดวก ทางทีมพัฒนา OpenLDAP ได้สร้างคำสั่ง slaptest เพื่อใช้ในการเปลี่ยนคอนฟิกแบบเก่าไฟล์เดียว ให้เป็นรูปแบบใหม่ได้ ในบทความนี้จะแสดงขั้นตอนการติดตั้งและคอนฟิก OpenLDAP บนเครื่อง Fedora 13 (x86_64) ติดตั้ง openldap ใช้คำสั่ง rpm เพื่อตรวจสอบการติดตั้ง openldap ว่ามีอยู่แล้วหรือไม่ [root@fc13-64a ~]# rpm [...]]]></description>
			<content:encoded><![CDATA[<p>การเปลี่ยนแปลงอย่างหนึ่งใน Fedora เวอร์ชั่นหลังๆ คือการเปลี่ยนวิธีการคอนฟิก OpenLDAP ซึ่งจะเป็นรูปแบบใหม่ที่มีมาตั้งแต่ OpenLDAP เวอร์ชั่น 2.3 เป็นต้นมา แต่ทาง Fedora เพิ่งเริ่มนำมาใช้</p>
<p>แบบเก่าไฟล์คอนฟิกหลักจะอยู่ในไฟล์ /etc/openldap/slapd.conf แต่แบบใหม่คอนฟิกจะถูกเก็บแยกเป็นไฟล์ LDIF เป็นโครงสร้างอยู่ในไดเร็คทอรี /etc/openldap/slapd.d/ และเมื่อรันเซอร์วิส ไฟล์เหล่านี้จะถูกอ่านเข้าไปใน LDAP เลย ซึ่งทำให้เราสามารถแก้ไขคอนฟิกเซิร์ฟเวอร์ ได้ เหมือนกับการแก้ไขข้อมูลอื่นๆ ใน LDAP</p>
<p>รายละเอียดเพิ่มเติมหาอ่านได้จาก ข้อมูลอ้างอิง Configuring slapd</p>
<p>เพื่อความสะดวก ทางทีมพัฒนา OpenLDAP ได้สร้างคำสั่ง slaptest เพื่อใช้ในการเปลี่ยนคอนฟิกแบบเก่าไฟล์เดียว ให้เป็นรูปแบบใหม่ได้</p>
<p>ในบทความนี้จะแสดงขั้นตอนการติดตั้งและคอนฟิก OpenLDAP บนเครื่อง Fedora 13 (x86_64)</p>
<p><span id="more-1126"></span></p>
<h4>ติดตั้ง openldap</h4>
<p>ใช้คำสั่ง rpm เพื่อตรวจสอบการติดตั้ง openldap ว่ามีอยู่แล้วหรือไม่</p>
<pre>[root@fc13-64a ~]# <strong>rpm -qa | grep openldap
</strong>openldap-2.4.21-4.fc13.x86_64</pre>
<p>เพื่อจะคอนฟิกเป็นเซิร์ฟเวอร์ได้ ต้องติดตั้งไฟล์ rpm เพิ่มเติม บางไฟล์หาได้จากแผ่นดีวีดีติดตั้ง</p>
<pre>[root@fc13-64a ~]# <strong>mount /dev/scd0 /media
</strong>mount: block device /dev/sr0 is write-protected, mounting read-only
[root@fc13-64a ~]# <strong>cd /media/Packages/</strong></pre>
<pre>[root@fc13-64a Packages]# <strong>rpm -i libtool-ltdl-2.2.6-20.fc13.x86_64.rpm
</strong>[root@fc13-64a Packages]# <strong>rpm -i openldap-clients-2.4.21-4.fc13.x86_64.rpm</strong></pre>
<p>ดาวน์โหลดไฟล์เพิ่มเติมจาก fc13 Everything แล้วติดตั้ง</p>
<pre>[root@fc13-64a Everything]# <strong>rpm -i openldap-servers-2.4.21-4.fc13.x86_64.rpm</strong></pre>
<p>ไฟล์คอนฟิกดีฟอลต์ของ OpenLDAP จะถูกติดตั้งอยู่ใน /etc/openldap/</p>
<pre>[root@fc13-64a ~]# <strong>cd /etc/openldap/</strong></pre>
<pre>[root@fc13-64a openldap]# <strong>ls -l
</strong>total 24
drwxr-xr-x. 2 root root 4096 Feb 24 16:19 cacerts
-rw-r--r--. 1 root root  245 Feb 24 16:19 ldap.conf
drwxr-xr-x  3 root root 4096 Jul 16 20:37 schema
-rw-r-----  1 root ldap 4153 Feb 24 16:19 slapd.conf.bak
drwx------  3 ldap ldap 4096 Jul 16 20:37 slapd.d</pre>
<h4>รันเซอร์วิส</h4>
<p>ใช้คำสั่ง service เพิ่มรัน slapd (OpenLDAP server)</p>
<pre>[root@fc13-64a ~]# <strong>service slapd start
</strong>/var/lib/ldap/__db.004<span style="color: #ff0000;"> is not owned by "ldap" </span>             [WARNING]
/var/lib/ldap/__db.001 is not owned by "ldap"              [WARNING]
/var/lib/ldap/__db.002 is not owned by "ldap"              [WARNING]
/var/lib/ldap/__db.006 is not owned by "ldap"              [WARNING]
/var/lib/ldap/__db.005 is not owned by "ldap"              [WARNING]
/var/lib/ldap/alock is not owned by "ldap"                 [WARNING]
/var/lib/ldap/__db.003 is not owned by "ldap"              [WARNING]
ln: accessing `/var/run/openldap/slapd.pid': No such file or directory</pre>
<p>มีข้อผิดพลาดฟ้องเรื่อง permission ไม่ถูกต้อง</p>
<pre>[root@fc13-64a ~]# <strong>ls -l /var/lib/ldap/
</strong>total 884
-rw------- 1 <span style="color: #ff0000;">root root</span>   2048 Jul 16 20:37 alock
-rw------- 1 root root  24576 Jul 16 20:37 __db.001
-rw------- 1 root root 212992 Jul 16 20:37 __db.002
-rw------- 1 root root 270336 Jul 16 20:37 __db.003
-rw------- 1 root root 163840 Jul 16 20:37 __db.004
-rw------- 1 root root 802816 Jul 16 20:37 __db.005
-rw------- 1 root root  32768 Jul 16 20:37 __db.006</pre>
<p>ใช้คำสัง chown เพื่อเปลี่ยนเจ้าของไฟล์ (owner)</p>
<pre>[root@fc13-64a ldap]# <strong>chown ldap.ldap *
</strong>[root@fc13-64a ldap]# <strong>ls -l
</strong>total 884
-rw------- 1 <span style="color: #0000ff;">ldap ldap   </span>2048 Jul 16 20:37 alock
-rw------- 1 ldap ldap  24576 Jul 16 20:37 __db.001
-rw------- 1 ldap ldap 212992 Jul 16 20:37 __db.002
-rw------- 1 ldap ldap 270336 Jul 16 20:37 __db.003
-rw------- 1 ldap ldap 163840 Jul 16 20:37 __db.004
-rw------- 1 ldap ldap 802816 Jul 16 20:37 __db.005
-rw------- 1 ldap ldap  32768 Jul 16 20:37 __db.006</pre>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิสอีกครั้ง</p>
<pre>[root@fc13-64a ldap]# <strong>service slapd start
</strong>Starting slapd:                                            [  OK  ]</pre>
<p>ใช้คำสั่ง ps เพื่อตรวจสอบ process</p>
<pre>[root@fc13-64a ldap]# <strong>ps -ef | grep ldap
</strong>ldap     22636     1  0 21:18 ?        00:00:00 /usr/sbin/slapd -h  ldap:/// -u ldap</pre>
<p>ใช้คำสั่ง service เพื่อปิดเซอร์วิส</p>
<pre>[root@fc13-64a ldap]# <strong>service slapd stop
</strong>Stopping slapd:                                            [  OK  ]</pre>
<p>แล้วทดลองรันเซอร์วิสอีกครั้ง จะมีข้อความฟ้องเรื่อง performance</p>
<pre>[root@fc13-64a ldap]# <strong>service slapd start
</strong>Checking configuration files for slapd:                    [WARNING]
<span style="color: #ff0000;">bdb_db_open: warning - no DB_CONFIG file found in directory /var/lib/ldap: (2).
Expect poor performance for suffix "dc=my-domain,dc=com".
</span>config file testing succeeded
Starting slapd:                                            [  OK  ]</pre>
<p>ปิดเซอร์วิสอีกครั้ง</p>
<pre>[root@fc13-64a ldap]# <strong>service slapd stop
</strong>Stopping slapd:                                            [  OK  ]</pre>
<p>เพื่อปรับปรุงเรื่อง performance ต้องสร้างไฟล์ DB_CONFIG  จากตัวอย่างไฟล์ใน /usr/share/doc/openldap-servers-2.4.21/</p>
<pre>[root@fc13-64a ldap]# <strong>cp /usr/share/doc/openldap-servers-2.4.21/DB_CONFIG.example DB_CONFIG
</strong>[root@fc13-64a ldap]# <strong>chown ldap.ldap DB_CONFIG
</strong>[root@fc13-64a ldap]# <strong>chmod 600 DB_CONFIG</strong></pre>
<p>ทดสอบการเปิด/ปิด เซอร์วิส ครั้งแรกจะมีฟ้องว่า มีการปรับเปลี่ยนคอนฟิก แล้วหลังจากนั้นก็สามารถรันได้ตามปกติ</p>
<pre>[root@fc13-64a ldap]# <strong>service slapd start
</strong>Checking configuration files for slapd:                    [WARNING]
<span style="color: #0000ff;">bdb_db_open: DB_CONFIG for suffix "dc=my-domain,dc=com" has changed.
Performing database recovery to activate new settings.
</span>bdb_db_open: database "dc=my-domain,dc=com": recovery skipped in read-only mode. Run manual recovery if errors are encountered.
config file testing succeeded
Starting slapd:                                            [  OK  ]</pre>
<pre>[root@fc13-64a ldap]# <strong>service slapd stop</strong>
Stopping slapd:                                            [  OK  ]</pre>
<pre>[root@fc13-64a ldap]# <strong>service slapd start</strong>
Starting slapd:                                            [  OK  ]</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/05/install_openldap_server_on_fedora_10">ติดตั้ง OpenLDAP Server บน Fedora 10</a></li>
<li><a href="http://www.openldap.org/doc/admin24/slapdconf2.html" target="_blank">OpenLDAP Software 2.4 Administrator&#8217;s Guide: Configuring slapd</a></li>
<li><a href="http://www.mirror.in.th/osarchive/fedora/releases/13/Everything/x86_64/os/Packages/" target="_blank">Fedora 13 x86_64 Everything</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/07/install_openldap_server_on_fedora_13/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ปัญหาการใช้ SSH Public Key Authentication บน Solaris</title>
		<link>http://spalinux.com/2010/06/ssh_public_key_authentication_problem_on_solaris</link>
		<comments>http://spalinux.com/2010/06/ssh_public_key_authentication_problem_on_solaris#comments</comments>
		<pubDate>Sat, 05 Jun 2010 10:40:51 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[secure shell]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1110</guid>
		<description><![CDATA[พยายามคอนฟิก Public Key Authentication เพื่อ login เข้าสู่เครื่องที่ติดตั้ง Solaris อยู่นาน ก็ไม่สามารถทำได้ แต่ในที่สุดก็สามารถหาปัญหาได้ เลยมาแชร์ประสบการณ์เผื่อจะเป็นประโยชน์ ทดสอบปัญหา เริ่มต้นเพิ่ม user บนเครื่องที่ติดตั้ง Solaris 10 สมมติว่าชื่อ user1 [root@solaris ~]# useradd user1 [root@solaris ~]# id user1 uid=502(user1) gid=1(other) groups=1(other) แก้ไข home ของ user1 ให้อยู่ใน /export/home/ และสร้างไดเร็คทอรี [root@solaris ~]# cat /etc/passwd ... user1:x:502:1::/export/home/user1:/bin/sh [root@solaris ~]# cd /export/home [root@solaris home]# mkdir user1 [root@solaris home]# chown [...]]]></description>
			<content:encoded><![CDATA[<p>พยายามคอนฟิก Public Key Authentication เพื่อ login เข้าสู่เครื่องที่ติดตั้ง Solaris อยู่นาน ก็ไม่สามารถทำได้ แต่ในที่สุดก็สามารถหาปัญหาได้ เลยมาแชร์ประสบการณ์เผื่อจะเป็นประโยชน์</p>
<p><span id="more-1110"></span></p>
<h4>ทดสอบปัญหา</h4>
<p>เริ่มต้นเพิ่ม user บนเครื่องที่ติดตั้ง Solaris 10 สมมติว่าชื่อ user1</p>
<pre>[root@solaris ~]# <strong>useradd user1
</strong>[root@solaris ~]# <strong>id user1
</strong>uid=502(user1) gid=1(other) groups=1(other)</pre>
<p>แก้ไข home ของ user1 ให้อยู่ใน /export/home/ และสร้างไดเร็คทอรี</p>
<pre>[root@solaris ~]# <strong>cat /etc/passwd
</strong>...
user1:x:502:1::<span style="color: #0000ff;">/export/home/user1</span>:/bin/sh</pre>
<pre>[root@solaris ~]# <strong>cd /export/home
</strong>[root@solaris home]# <strong>mkdir user1
</strong>[root@solaris home]# <strong>chown user1 user1/
</strong>[root@solaris home]# <strong>su - user1
</strong>[user1@solaris ~]$ <strong>pwd
</strong>/export/home/user1</pre>
<p>ต้องการให้ admin1 จากเครื่องที่ติดตั้ง linux สามารถ ssh ด้วย public key authentication เป็น user1 บนเครื่อง Solaris ได้</p>
<p>สร้าง public, private key ของ admin1</p>
<pre>[admin1@linux ~]$ <strong>ssh-keygen -t rsa
</strong>Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin1/.ssh/id_rsa):
Created directory '/home/admin1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/admin1/.ssh/id_rsa.
Your public key has been saved in /home/admin1/.ssh/id_rsa.pub.</pre>
<pre>[admin1@linux ~]$ <strong>cat .ssh/id_rsa.pub
</strong><span style="color: #0000ff;">ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtMbbgeFnn6vEo3IAVh... admin1@linux</span></pre>
<p>copy ไฟล์ id_rsa.pub ของ admin1 ไปใส่ไว้ในไฟล์ authorized_keys ของ user1 บนเครื่อง Solaris</p>
<pre>[user1@solaris ~]$ <strong>cat .ssh/authorized_keys
</strong><span style="color: #0000ff;">ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtMbbgeFnn6vEo3IAVh... admin1@linux</span></pre>
<p>ทดสอบ ssh จากเครื่อง linux</p>
<pre>[admin1@linux ~]$ <strong>ssh -l user1 solaris
</strong>The authenticity of host 'solaris (192.168.1.2)' can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'solaris' (RSA) to the list of known hosts.
Password:</pre>
<p>ขึ้นให้ใส่ password ไม่สามารถ login ด้วย public key authentication ได้</p>
<h4>วิธีการแก้ไขปัญหา</h4>
<p>หลังจากพยายามอยู่นาน ก็พบว่า ssh จะตรวจสอบสถานะ password ของผู้ใช้ด้วย ซึ่งถ้าดูในไฟล์ /etc/shadow จะเห็นว่า user1 จะถูก lock อยู่</p>
<pre>[root@solaris ~]# <strong>cat /etc/shadow
</strong>...
user1:<span style="color: #ff0000;"><strong>*LK*</strong></span>:::::::</pre>
<p>ฟิลด์ที่สองในไฟล์ /etc/shadow คือ encrypted password คำอธิบายจาก man ของ shadow คือ</p>
<pre># <strong>man shadow
</strong>...
     password        An encrypted password for the user generated
                     by crypt(3C), a lock string to indicate that
                     the login is not accessible, or  no  string,
                     which  shows  that  there is no password for
                     the login.</pre>
<pre>                     The lock string is defined as <span style="color: #ff0000;"> *LK*</span>  in  the
                     first four characters of the password field.
...</pre>
<p>การแก้ไขคือ ลบตัวอักษร LK ออก เช่นให้เหลือแต่เครื่องหมาย *</p>
<pre>[root@solaris ~]# <strong>cat /etc/shadow
</strong>...
user1:<span style="color: #ff0000;">*</span>:::::::</pre>
<p>ทดสอบ ssh จากเครื่อง linux อีกครั้ง ก็จะได้ตามที่ต้องการ</p>
<pre>[admin1@linux ~]$ <strong>ssh -l user1 solaris
</strong>[user1@solaris ~]$</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/10/ssh_secure_shell_login_using_public_key_authentication">SSH – Secure Shell ล็อกอินด้วย Public Key Authentication</a></li>
<li><a href="http://forums.sun.com/thread.jspa?threadID=5229706" target="_blank">Sun Networking Services and Protocols &#8211; SSH PermitEmptyPasswords with PASSREQ</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/06/ssh_public_key_authentication_problem_on_solaris/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>รันโปรเซสเป็น user อื่น</title>
		<link>http://spalinux.com/2010/03/run_process_as_another_user</link>
		<comments>http://spalinux.com/2010/03/run_process_as_another_user#comments</comments>
		<pubDate>Sat, 06 Mar 2010 05:52:51 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Linux Shell]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[unix process]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1088</guid>
		<description><![CDATA[เป็นวิธีง่ายๆ เพื่อให้ผู้ใช้ root สามารถรันโปรเซสหรือโปรแกรมบน Linux/UNIX ภายใต้สิทธิหรือ permission ผู้ใช้ user อื่นบนเครื่องเดียวกัน คำสั่งที่ใช้คือ su ตามด้วยออปชั่น &#8216;-c&#8217; รูปแบบการใช้คำสั่งคือ # su - &#60;user_name&#62; -c "&#60;command&#62;" ตัวอย่าง root รันคำสั่ง id ภายใต้สิทธิผู้ใช้ชื่อ user1 # su - user1 -c "id" uid=501(user1) gid=100(users) groups=100(users) ข้อมูลอ้างอิง &#8216;su&#8217; man page]]></description>
			<content:encoded><![CDATA[<p>เป็นวิธีง่ายๆ เพื่อให้ผู้ใช้ root สามารถรันโปรเซสหรือโปรแกรมบน Linux/UNIX ภายใต้สิทธิหรือ permission ผู้ใช้ user อื่นบนเครื่องเดียวกัน</p>
<p><span id="more-1088"></span>คำสั่งที่ใช้คือ su ตามด้วยออปชั่น &#8216;-c&#8217; รูปแบบการใช้คำสั่งคือ</p>
<pre># su - &lt;user_name&gt; -c "&lt;command&gt;"</pre>
<p>ตัวอย่าง root รันคำสั่ง id ภายใต้สิทธิผู้ใช้ชื่อ user1</p>
<pre># <strong>su - user1 -c "id"
</strong>uid=501(user1) gid=100(users) groups=100(users)</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li>&#8216;su&#8217; man page</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/03/run_process_as_another_user/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้งและทดสอบ FreeRADIUS เบื้องต้น</title>
		<link>http://spalinux.com/2009/11/basic_install_freeradius</link>
		<comments>http://spalinux.com/2009/11/basic_install_freeradius#comments</comments>
		<pubDate>Sat, 28 Nov 2009 07:44:09 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[RADIUS]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=974</guid>
		<description><![CDATA[FreeRADIUS เป็นโปรแกรมที่ทำหน้าที่ RADIUS แบบฟรี ที่คนใช้งานกันมากที่สุด โดยมีคุณสมบัติเทียบเท่ากับ commercial RADIUS หลายๆ ตัว บทความนี้จะกล่าวถึงวิธีการติดตั้ง และทดสอบ FreeRADIUS ในเบื้องต้น เพื่อจะสามารถต่อยอด และคอนฟิกอื่นๆ เพิ่มเติมได้ ติดตั้งไฟล์ rpm ในที่นี้จะทดสอบบน Fedora 11 (x86_64) โดยใช้ไฟล์ rpm ในส่วน updates เพื่อติดตั้งและใช้งาน ใช้คำสั่ง rpm เพื่อติดตั้งไฟล์ ต่างๆ ดังนี้ [root@fc11-64a ~]# rpm -i freeradius-libs-2.1.7-1.fc11.x86_64.rpm [root@fc11-64a ~]# rpm -i freeradius-2.1.7-1.fc11.x86_64.rpm [root@fc11-64a ~]# rpm -i freeradius-utils-2.1.7-1.fc11.x86_64.rpm หมายเหตุ การติดตั้ง freeradius-utils จำเป็นต้องมี perl(DBI) ติดตั้งอยู่ก่อนแล้ว ตัวอย่าง [...]]]></description>
			<content:encoded><![CDATA[<p>FreeRADIUS เป็นโปรแกรมที่ทำหน้าที่ RADIUS แบบฟรี ที่คนใช้งานกันมากที่สุด โดยมีคุณสมบัติเทียบเท่ากับ commercial RADIUS หลายๆ ตัว</p>
<p>บทความนี้จะกล่าวถึงวิธีการติดตั้ง และทดสอบ FreeRADIUS ในเบื้องต้น เพื่อจะสามารถต่อยอด และคอนฟิกอื่นๆ เพิ่มเติมได้</p>
<h4><span id="more-974"></span><br />
ติดตั้งไฟล์ rpm</h4>
<p>ในที่นี้จะทดสอบบน Fedora 11 (x86_64) โดยใช้ไฟล์ rpm ในส่วน updates เพื่อติดตั้งและใช้งาน</p>
<p>ใช้คำสั่ง rpm เพื่อติดตั้งไฟล์ ต่างๆ ดังนี้</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i freeradius-libs-2.1.7-1.fc11.x86_64.rpm
</strong>[root@fc11-64a ~]# <strong>rpm -i freeradius-2.1.7-1.fc11.x86_64.rpm
</strong>[root@fc11-64a ~]# <strong>rpm -i freeradius-utils-2.1.7-1.fc11.x86_64.rpm</strong></pre>
<p>หมายเหตุ การติดตั้ง freeradius-utils จำเป็นต้องมี perl(DBI) ติดตั้งอยู่ก่อนแล้ว</p>
<p>ตัวอย่าง error หากไม่มี perl(DBI) ติดตั้งอยู่</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i freeradius-utils-2.1.7-1.fc11.x86_64.rpm
</strong>error: Failed dependencies:
        perl(DBI) is needed by freeradius-utils-2.1.7-1.fc11.x86_64</pre>
<p>วิธีการแก้ไขปัญหา</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i perl-DBI-1.607-2.fc11.x86_64.rpm</strong></pre>
<h4>รันเซอร์วิส radiusd</h4>
<p>หลังจากการติดตั้ง ใช้คำสั่ง service เพื่อรันเซอร์วิส radiusd</p>
<pre>[root@fc11-64a ~]# <strong>service radiusd start
</strong>Starting RADIUS server:                                    [<strong><span style="color: #ff0000;">FAILED</span></strong>]</pre>
<p>หากยังไม่แก้ไขไฟล์คอนฟิกเลย จะไม่สามารถรันเซอร์วิส radiusd ได้ ขึ้น [FAILED]</p>
<p>เมื่อเกิดปัญหาในการใช้งาน radiusd ไฟล์หนึ่งที่สามารถตรวจสอบปัญหาได้คือไฟล์ /var/log/radius/radius.log</p>
<pre>[root@fc11-64a ~]# <strong>tail /var/log/radius/radius.log
</strong>Sat Nov 28 12:15:09 2009 : Error: rlm_eap: SSL error error:02001002:system library:fopen:<span style="color: #ff0000;">No such file or directory
</span>Sat Nov 28 12:15:09 2009 : Error: rlm_eap_tls: <span style="color: #ff0000;">Error reading certificate file /etc/raddb/certs/server.pem
</span>Sat Nov 28 12:15:09 2009 : Error: rlm_eap: Failed to initialize type tls
Sat Nov 28 12:15:09 2009 : Error: /etc/raddb/eap.conf[17]: Instantiation failed for module "eap"
Sat Nov 28 12:15:09 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[223]: Failed to find module "eap".
Sat Nov 28 12:15:09 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[176]: Errors parsing authenticate section.
Sat Nov 28 12:15:09 2009 : Error: Failed to load virtual server inner-tunnel</pre>
<p>ปัญหานี้คือไม่มีไฟล์ /etc/raddb/certs/server.pem ซึ่งเป็น certificate สำหรับการทำ EAP</p>
<p>วิธีการแก้ไขคือสร้างไฟล์ server.pem โดยเข้าไปในไดเร็คทอรี /etc/raddb/certs/ แล้วรันคำสั่ง bootstrap ซึ่งจะสร้างไฟล์ certificate ขึ้นมา</p>
<p>หมายเหตุ เพื่อความง่าย ในที่นี้จะสร้าง certificate ไฟล์ เพื่อทดสอบการใช้งาน radiusd เท่านั้น ในการใช้งานจริงก่อนที่จะสร้าง ควรจะแก้ไขคอนฟิก เพื่อระบุ Certificate Details เพื่อแสดงชื่อหน่วยงานให้ถูกต้อง</p>
<pre>[root@fc11-64a ~]# c<strong>d /etc/raddb/certs/
</strong>[root@fc11-64a certs]# <strong>./bootstrap
</strong>openssl dhparam -out dh 1024
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
.................+......................................................................................................+...+.........+.....+.......................+...................................................................................................+......................................+........................................................................................................+.................................................................+....................+...................................................................................+...................+.......................................+............................................................................+..........................................+.............+....................................+..............................................+...+.....................+...+.....+...............+.............................+..................+...................................................+.....+.................+............................................+.......+................................................................................................+....+.....+............................................................................................................................................................................................................................................+......................+........................................................................................................................................................................................................................................+............+............................+..................+.............................................................................................................................+.....................................................++*++*++*
openssl req -new  -out server.csr -keyout server.key -config ./server.cnf
Generating a 2048 bit RSA private key
.......................+++
.....+++
writing new private key to 'server.key'
-----
openssl req -new -x509 -keyout ca.key -out ca.pem \
                -days `grep default_days ca.cnf | sed 's/.*=//;s/^ *//'` -config ./ca.cnf
Generating a 2048 bit RSA private key
....................................+++
........+++
writing new private key to 'ca.key'
-----
openssl ca -batch -keyfile ca.key -cert ca.pem -in server.csr  -key `grep output_password ca.cnf | sed 's/.*=//;s/^ *//'` -out server.crt -extensions xpserver_ext -extfile xpextensions -config ./server.cnf
Using configuration from ./server.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Nov 28 05:20:32 2009 GMT
            Not After : Nov 28 05:20:32 2010 GMT
        Subject:
            countryName               = FR
            stateOrProvinceName       = Radius
            organizationName          = Example Inc.
            commonName                = Example Server Certificate
            emailAddress              = admin@example.com
        X509v3 extensions:
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
Certificate is to be certified until Nov 28 05:20:32 2010 GMT (365 days)</pre>
<pre>Write out database with 1 new entries
Data Base Updated
openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12  -passin pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'` -passout pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'`
openssl pkcs12 -in server.p12 -out <span style="color: #3366ff;">server.pem </span>-passin pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'` -passout pass:`grep output_password server.cnf | sed 's/.*=//;s/^ *//'`
MAC verified OK
openssl x509 -inform PEM -outform DER -in ca.pem -out ca.der</pre>
<p>หลังจากสร้างแล้ว ใช้คำสั่ง service เพื่อรันเซอร์วิส radiusd อีกครั้ง</p>
<pre>[root@fc11-64a certs]# <strong>service radiusd start
</strong>Starting RADIUS server:                                    [<span style="color: #ff0000;">FAILED</span>]</pre>
<p>รันครั้งนี้ ก็ยัง [FAILED] อยู่ ถ้าตรวจสอบดูไฟล์ radius.log มีข้อความ &#8220;Permission denied&#8221; ขึ้น ซึ่งหมายถึง radiusd ไม่สามารถอ่านไฟล์ server.pem ได้</p>
<pre>[root@fc11-64a ~]# <strong>tail /var/log/radius/radius.log
</strong>...
Sat Nov 28 12:21:38 2009 : Error: rlm_eap: SSL error error:0200100D:system library:fopen:<span style="color: #ff0000;">Permission denied
</span>Sat Nov 28 12:21:38 2009 : Error: rlm_eap_tls: <span style="color: #ff0000;">Error reading certificate file /etc/raddb/certs/server.pem
</span>Sat Nov 28 12:21:38 2009 : Error: rlm_eap: Failed to initialize type tls
Sat Nov 28 12:21:38 2009 : Error: /etc/raddb/eap.conf[17]: Instantiation failed for module "eap"
Sat Nov 28 12:21:38 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[223]: Failed to find module "eap".
Sat Nov 28 12:21:38 2009 : Error: /etc/raddb/sites-enabled/inner-tunnel[176]: Errors parsing authenticate section.
Sat Nov 28 12:21:38 2009 : Error: Failed to load virtual server inner-tunnel</pre>
<p>ปัญหานี้เกิดจากเราใช้ root เพื่อรันคำสั่ง bootstrap แล้วไฟล์ที่ถูกสร้างขึ้น owner, group จะเป็น root ทั้งหมด แต่ radiusd รันภายใต้ owner, group ที่ชื่อ radiusd ทำให้ไม่สามารถอ่านไฟล์ ที่ root สร้างขึ้นได้</p>
<p>ใช้คำสั่ง ls เพื่อตรวจสอบไฟล์ที่ root สร้างขึ้น</p>
<pre>[root@fc11-64a certs]# <strong>ls -lrt
</strong>total 108
-rw-r----- 1 root radiusd  578 2009-09-15 22:29 xpextensions
-rw-r----- 1 root radiusd 1123 2009-09-15 22:29 server.cnf
-rw-r----- 1 root radiusd 7819 2009-09-15 22:29 README
-rw-r----- 1 root radiusd 4302 2009-09-15 22:29 Makefile
-rw-r----- 1 root radiusd 1109 2009-09-15 22:29 client.cnf
-rw-r----- 1 root radiusd 1288 2009-09-15 22:29 ca.cnf
-rwxr-x--- 1 root radiusd 2072 2009-09-15 22:29 bootstrap
-rw-r----- 1 root root     245 2009-11-28 12:20 dh
-rw-r----- 1 root root    5120 2009-11-28 12:20 random
-rw-r----- 1 root root    1751 2009-11-28 12:20 server.key
-rw-r----- 1 root root    1062 2009-11-28 12:20 server.csr
-rw-r----- 1 root root    1743 2009-11-28 12:20 ca.key
-rw-r----- 1 root root    1675 2009-11-28 12:20 ca.pem
-rw-r----- 1 root root       0 2009-11-28 12:20 index.txt.old
-rw-r----- 1 root root       3 2009-11-28 12:20 serial.old
-rw-r----- 1 root root       3 2009-11-28 12:20 serial
-rw-r----- 1 root root      21 2009-11-28 12:20 index.txt.attr
-rw-r----- 1 root root     120 2009-11-28 12:20 index.txt
-rw-r----- 1 root root    4210 2009-11-28 12:20 server.crt
-rw-r----- 1 root root    4210 2009-11-28 12:20 01.pem
-rw-r----- 1 root root    2533 2009-11-28 12:20 server.p12
<span style="color: #ff0000;">-rw-r----- 1 root root    3503 2009-11-28 12:20 server.pem
</span>-rw-r----- 1 root root    1195 2009-11-28 12:20 ca.der</pre>
<p>การแก้ไขปัญหา ทำได้โดยการเปลี่ยน permission ของไฟล์ เพื่อให้ radiusd สามารถอ่านไฟล์ได้ ในที่นี้เปลี่ยนแค่ group ของไฟล์ก็เพียงพอแล้ว และเพื่อความปลอดภัยของระบบด้วย</p>
<p>ใช้คำสั่ง chgrp เพื่อเปลี่ยน group ของไฟล์</p>
<pre>[root@fc11-64a certs]# <strong>chgrp radiusd *
</strong>[root@fc11-64a certs]# <strong>ls -lrt
</strong>total 108
-rw-r----- 1 root radiusd  578 2009-09-15 22:29 xpextensions
-rw-r----- 1 root radiusd 1123 2009-09-15 22:29 server.cnf
-rw-r----- 1 root radiusd 7819 2009-09-15 22:29 README
-rw-r----- 1 root radiusd 4302 2009-09-15 22:29 Makefile
-rw-r----- 1 root radiusd 1109 2009-09-15 22:29 client.cnf
-rw-r----- 1 root radiusd 1288 2009-09-15 22:29 ca.cnf
-rwxr-x--- 1 root radiusd 2072 2009-09-15 22:29 bootstrap
-rw-r----- 1 root radiusd  245 2009-11-28 12:20 dh
-rw-r----- 1 root radiusd 5120 2009-11-28 12:20 random
-rw-r----- 1 root radiusd 1751 2009-11-28 12:20 server.key
-rw-r----- 1 root radiusd 1062 2009-11-28 12:20 server.csr
-rw-r----- 1 root radiusd 1743 2009-11-28 12:20 ca.key
-rw-r----- 1 root radiusd 1675 2009-11-28 12:20 ca.pem
-rw-r----- 1 root radiusd    0 2009-11-28 12:20 index.txt.old
-rw-r----- 1 root radiusd    3 2009-11-28 12:20 serial.old
-rw-r----- 1 root radiusd    3 2009-11-28 12:20 serial
-rw-r----- 1 root radiusd   21 2009-11-28 12:20 index.txt.attr
-rw-r----- 1 root radiusd  120 2009-11-28 12:20 index.txt
-rw-r----- 1 root radiusd 4210 2009-11-28 12:20 server.crt
-rw-r----- 1 root radiusd 4210 2009-11-28 12:20 01.pem
-rw-r----- 1 root radiusd 2533 2009-11-28 12:20 server.p12
<span style="color: #0000ff;">-rw-r----- 1 root radiusd 3503 2009-11-28 12:20 server.pem
</span>-rw-r----- 1 root radiusd 1195 2009-11-28 12:20 ca.der</pre>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส radiusd อีกครั้ง</p>
<pre>[root@fc11-64a certs]# <strong>service radiusd start
</strong>Starting RADIUS server:                                    [  OK  ]</pre>
<p>ครั้งนี้จะสามารถรันได้ [ OK ] หากดูในไฟล์ radius.log จะมีข้อความดังนี้เกิดขึ้น</p>
<pre>[root@fc11-64a ~]# <strong>tail /var/log/radius/radius.log
</strong>...
Sat Nov 28 12:23:10 2009 : Info: Loaded virtual server inner-tunnel
Sat Nov 28 12:23:11 2009 : Info: Loaded virtual server &lt;default&gt;
Sat Nov 28 12:23:11 2009 : Info: Ready to process requests.</pre>
<p>ใช้คำสั่ง ps เพื่อ ตรวจสอบ process ของ radiusd</p>
<pre>[root@fc11-64a certs]# <strong>ps -ef | grep radiusd
</strong>radiusd   1772     1  0 12:23 ?        00:00:00 /usr/sbin/radiusd
root      1783  1393  0 12:23 pts/0    00:00:00 grep radiusd</pre>
<p>ใช้คำสั่ง netstat เพื่อตรวจสอบพอร์ตของ radiusd ที่ใช้</p>
<pre>[root@fc11-64a raddb]# <strong>netstat -a | grep udp
</strong>...
udp        0      0 *:radius                    *:*
udp        0      0 *:radius-acct               *:*
udp        0      0 *:tdp-suite                 *:*</pre>
<p>โดยดีฟอลต์ของ FreeRADIUS จะใช้พอร์ต UDP 1812, 1813, 1814 ในการทำงาน</p>
<p>ดูการ map ชื่อพอร์ตและเลขหมายของพอร์ตในไฟล์ /etc/services</p>
<pre>[root@fc11-64a ~]# <strong>cat /etc/services
</strong>...
radius          1812/udp                        # Radius
radius-acct     1813/udp        radacct         # Radius Accounting
tdp-suite       1814/udp                # TDP Suite</pre>
<h4>ทดสอบด้วย radtest</h4>
<p>จากการติดตั้ง freeradius-utils จะมีโปรแกรม radius client มาให้ด้วย คำสั่งหนึ่งที่ใช้ในการทดสอบอย่างง่ายๆ คือ radtest</p>
<pre>[root@fc11-64a ~]# <strong>radtest</strong>
Usage: radtest user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname]</pre>
<p>พารามิเตอร์ที่ต้องระบุในการใช้คำสั่ง radtest คือ</p>
<ul>
<li>user                              ชื่อ username ที่ต้องการ authenticate</li>
<li>passwd                        รหัสผ่าน password สำหรับ username</li>
<li>radius-server            เป็น IP Address ของเครื่องที่รัน radiusd ทำหน้าที่เป็น RADIUS Server</li>
<li>nas-port-number    ระบุหมายเลขพอร์ต สำหรับการทดสอบจะใช้เป็นตัวเลขอะไรก็ได้</li>
<li>secret                           เป็น shared secret เพื่อต้องระบุใน RADIUS Server เพื่อเป็นการอนุญาตว่า เครื่อง RADIUS Client ใดสามารถมา authenticate ได้บ้าง</li>
</ul>
<p>ทดสอบการส่ง user, password ไปยัง radius server ที่ติดตั้ง ในที่นนี้ทดสอบบนเครื่องเดียวกัน ระบุเป็น 127.0.0.1</p>
<pre>[root@fc11-64a ~]# <strong>radtest user1 password1 127.0.0.1 1 secret1
</strong>Sending Access-Request of id 207 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <strong><span style="color: #ff0000;">Access-Reject</span></strong> packet from host 127.0.0.1 port 1812, id=207, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)!  (<span style="color: #ff0000;">Shared secret is incorrect.</span>)
Sending Access-Request of id 207 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: Access-Reject packet from host 127.0.0.1 port 1812, id=207, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)!  (Shared secret is incorrect.)
Sending Access-Request of id 207 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: Access-Reject packet from host 127.0.0.1 port 1812, id=207, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)!  (Shared secret is incorrect.)
radclient: no response from server for ID 207 socket 3</pre>
<p>ผลจากการรันคำสั่ง radtest จะฟ้อง &#8220;Access-Reject&#8221; เนื่องจาก &#8220;Shared secret is incorrect&#8221;</p>
<p>การแก้ไข คือต้องระบุ shared secret ให้ถูกต้อง</p>
<p>ในไฟล์ /etc/raddb/clients.conf จะมีคอนฟิกระบุ เครื่อง client ที่สามารถส่งข้อมูลมา authenticate ได้ แต่ต้องระบุ shared secret ให้ถูกต้อง</p>
<p>หากตัดส่วน comment &#8221;#&#8221; ออก ดีฟอลต์จากการติดตั้ง จะมีคอนฟิกสำหรับเครื่อง localhost ดังนี้</p>
<pre>client localhost {
    ipaddr = 127.0.0.1
    secret      = testing123
    require_message_authenticator = no
    nastype     = other
}</pre>
<p>จากคอนฟิก แปลว่าหากมีการส่ง request จากเครื่อง localhost หรือ 127.0.01 ต้องระบุ shared secret เป็น testing123 จึงจะใช้ server ได้</p>
<p>ทดสอบคำสั่ง radtest ด้วย shared secret ที่ถูกต้อง</p>
<pre>[root@fc11-64a ~]# <strong>radtest user1 password1 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 58 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <span style="color: #ff0000;">Access-Reject packet</span> from host 127.0.0.1 port 1812, id=58, length=20</pre>
<p>ผลการรันยังคงได้เป็น &#8220;Access-Reject&#8221; อยู่ เนื่องจาก ไม่มี username ที่ใช้ใน Server</p>
<p>ดีฟอลต์คอนฟิกเบื้องต้น จะเก็บไฟล์ username, password ไว้ในไฟล์ /etc/raddb/users โดยมีบรรทัดสุดท้ายอธิบายว่า ถ้าไม่ match หรือไม่มี username, password ที่คอนฟิกไว้ จะ denied การใช้งาน</p>
<p># On no match, the user is denied access.</p>
<p>แก้ไขไฟล์ /etc/raddb/users โดยเพิ่ม username, password ที่ต้องการ</p>
<pre>...
<span style="color: #0000ff;">user1  Cleartext-Password := "password1"
       Reply-Message = "Hello, %{User-Name}"</span></pre>
<pre># On no match, the user is denied access.</pre>
<p>ใช้คำสั่ง service เพื่อรีโหลดคอนฟิกของ radius ใหม่</p>
<pre>[root@fc11-64a ~]# <strong>service radiusd reload
</strong>Reloading RADIUS server:                                   [  OK  ]</pre>
<p>ทดสอบคำสั่ง radtest โดยระบุ user, password ที่ถูกต้องจากไฟล์ /etc/raddb/users จะได้รับ &#8220;Access-Accept&#8221;</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user1 password1 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 49 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <strong><span style="color: #0000ff;">Access-Accept</span></strong> packet from host 127.0.0.1 port 1812, id=49, length=34
<span style="color: #0000ff;">        Reply-Message = "Hello, user1"</span></pre>
<p>ทดสอบด้วย user ที่มีอยู่ในไฟล์ /etc/raddb/users แต่ระบุ password ผิด จะได้รับ &#8220;Access-Reject&#8221; แต่จะได้ &#8220;Reply-Message&#8221; ของ username นั้น กลับมาด้วย</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user1 password2 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 76 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password2"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <span style="color: #ff0000;"><strong>Access-Reject</strong></span> packet from host 127.0.0.1 port 1812, id=76, length=34
<span style="color: #0000ff;">        Reply-Message = "Hello, user1"</span></pre>
<p>ทดสอบด้วย user ที่ไม่มีอยู่ในไฟล์ /etc/raddb/users  จะได้รับ &#8220;Access-Reject&#8221;</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user2 password2 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 91 to 127.0.0.1 port 1812
        User-Name = "user2"
        User-Password = "password2"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: <span style="color: #ff0000;"><strong>Access-Reject </strong></span>packet from host 127.0.0.1 port 1812, id=91, length=20</pre>
<h4>รัน radiusd ในโหมด debug</h4>
<p>เมื่อเกิดปัญหาการคอนฟิกหรือการทำงานของ FreeRADIUS สิ่งหนึ่งที่ช่วยทำให้สามารถตรวจสอบรายละเอียดและแก้ไขปัญหาที่เกิดขึ้นได้ คือรัน radiusd ในโหมด debug ซึ่งหน้าจอจะแสดงขั้นตอนการทำงานของ radiusd อย่างละเอียด ทำให้เราสามารถทราบได้ว่า ปัญหาเกิดขึ้นที่จุดไหน</p>
<p>ใช้คำสั่ง service เพื่อหยุดรัน radiusd ในโหมดปกติ</p>
<pre>[root@fc11-64a ~]# <strong>service radiusd stop
</strong>Stopping RADIUS server:                                    [  OK  ]</pre>
<p>รันคำสั่ง radiusd ตามด้วย ออปชั่น &#8216;-X&#8217; เพื่อรันในโหมด debug หน้าจอจะแสดงรายละเอียดในการทำงานของ radiusd สังเกตว่าเมื่อรันโหมด debug จะไม่กลับคืนสู่ prompt</p>
<p>หากต้องการหยุดรันในโหมด debug สามารถทำได้โดยกด [Ctrl-C]</p>
<p>ตัวอย่างการรัน radiusd ในโหมด debug</p>
<pre>[root@fc11-64a ~]# <strong>radiusd -X
</strong>FreeRADIUS Version 2.1.7, for host x86_64-redhat-linux-gnu, built on Sep 15 2009 at 11:29:29
Copyright (C) 1999-2009 The FreeRADIUS server project and contributors.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
You may redistribute copies of FreeRADIUS under the terms of the
GNU General Public License v2.
Starting - reading configuration files ...
including configuration file /etc/raddb/radiusd.conf
including configuration file /etc/raddb/proxy.conf
including configuration file /etc/raddb/clients.conf
including files in directory /etc/raddb/modules/
including configuration file /etc/raddb/modules/acct_unique
including configuration file /etc/raddb/modules/always
including configuration file /etc/raddb/modules/attr_filter
including configuration file /etc/raddb/modules/attr_rewrite
including configuration file /etc/raddb/modules/chap
including configuration file /etc/raddb/modules/checkval
including configuration file /etc/raddb/modules/counter
including configuration file /etc/raddb/modules/cui
including configuration file /etc/raddb/modules/detail
including configuration file /etc/raddb/modules/detail.example.com
including configuration file /etc/raddb/modules/detail.log
including configuration file /etc/raddb/modules/digest
including configuration file /etc/raddb/modules/echo
including configuration file /etc/raddb/modules/etc_group
including configuration file /etc/raddb/modules/exec
including configuration file /etc/raddb/modules/expiration
including configuration file /etc/raddb/modules/expr
including configuration file /etc/raddb/modules/files
including configuration file /etc/raddb/modules/inner-eap
including configuration file /etc/raddb/modules/ippool
including configuration file /etc/raddb/modules/linelog
including configuration file /etc/raddb/modules/logintime
including configuration file /etc/raddb/modules/mac2ip
including configuration file /etc/raddb/modules/mac2vlan
including configuration file /etc/raddb/modules/mschap
including configuration file /etc/raddb/modules/otp
including configuration file /etc/raddb/modules/pam
including configuration file /etc/raddb/modules/pap
including configuration file /etc/raddb/modules/passwd
including configuration file /etc/raddb/modules/perl
including configuration file /etc/raddb/modules/policy
including configuration file /etc/raddb/modules/preprocess
including configuration file /etc/raddb/modules/radutmp
including configuration file /etc/raddb/modules/realm
including configuration file /etc/raddb/modules/smbpasswd
including configuration file /etc/raddb/modules/smsotp
including configuration file /etc/raddb/modules/sql_log
including configuration file /etc/raddb/modules/sqlcounter_expire_on_login
including configuration file /etc/raddb/modules/sradutmp
including configuration file /etc/raddb/modules/unix
including configuration file /etc/raddb/modules/wimax
including configuration file /etc/raddb/eap.conf
including configuration file /etc/raddb/policy.conf
including files in directory /etc/raddb/sites-enabled/
including configuration file /etc/raddb/sites-enabled/control-socket
including configuration file /etc/raddb/sites-enabled/default
including configuration file /etc/raddb/sites-enabled/inner-tunnel
group = radiusd
user = radiusd
including dictionary file /etc/raddb/dictionary
main {
        prefix = "/usr"
        localstatedir = "/var"
        logdir = "/var/log/radius"
        libdir = "/usr/lib64/freeradius"
        radacctdir = "/var/log/radius/radacct"
        hostname_lookups = no
        max_request_time = 30
        cleanup_delay = 5
        max_requests = 1024
        allow_core_dumps = no
        pidfile = "/var/run/radiusd/radiusd.pid"
        checkrad = "/usr/sbin/checkrad"
        debug_level = 0
        proxy_requests = yes
 log {
        stripped_names = no
        auth = no
        auth_badpass = no
        auth_goodpass = no
 }
 security {
        max_attributes = 200
        reject_delay = 1
        status_server = yes
 }
}
radiusd: #### Loading Realms and Home Servers ####
 proxy server {
        retry_delay = 5
        retry_count = 3
        default_fallback = no
        dead_time = 120
        wake_all_if_all_dead = no
 }
 home_server localhost {
        ipaddr = 127.0.0.1
        port = 1812
        type = "auth"
        secret = "testing123"
        response_window = 20
        max_outstanding = 65536
        require_message_authenticator = no
        zombie_period = 40
        status_check = "status-server"
        ping_interval = 30
        check_interval = 30
        num_answers_to_alive = 3
        num_pings_to_alive = 3
        revive_interval = 120
        status_check_timeout = 4
        irt = 2
        mrt = 16
        mrc = 5
        mrd = 30
 }
 home_server_pool my_auth_failover {
        type = fail-over
        home_server = localhost
 }
 realm example.com {
        auth_pool = my_auth_failover
 }
 realm LOCAL {
 }
radiusd: #### Loading Clients ####
 client localhost {
        ipaddr = 127.0.0.1
        require_message_authenticator = no
        secret = "testing123"
        nastype = "other"
 }
radiusd: #### Instantiating modules ####
 instantiate {
 Module: Linked to module rlm_exec
 Module: Instantiating exec
  exec {
        wait = no
        input_pairs = "request"
        shell_escape = yes
  }
 Module: Linked to module rlm_expr
 Module: Instantiating expr
 Module: Linked to module rlm_expiration
 Module: Instantiating expiration
  expiration {
        reply-message = "Password Has Expired  "
  }
 Module: Linked to module rlm_logintime
 Module: Instantiating logintime
  logintime {
        reply-message = "You are calling outside your allowed timespan  "
        minimum-timeout = 60
  }
 }
radiusd: #### Loading Virtual Servers ####
server inner-tunnel {
 modules {
 Module: Checking authenticate {...} for more modules to load
 Module: Linked to module rlm_pap
 Module: Instantiating pap
  pap {
        encryption_scheme = "auto"
        auto_header = no
  }
 Module: Linked to module rlm_chap
 Module: Instantiating chap
 Module: Linked to module rlm_mschap
 Module: Instantiating mschap
  mschap {
        use_mppe = yes
        require_encryption = no
        require_strong = no
        with_ntdomain_hack = no
  }
 Module: Linked to module rlm_unix
 Module: Instantiating unix
  unix {
        radwtmp = "/var/log/radius/radwtmp"
  }
 Module: Linked to module rlm_eap
 Module: Instantiating eap
  eap {
        default_eap_type = "md5"
        timer_expire = 60
        ignore_unknown_eap_types = no
        cisco_accounting_username_bug = no
        max_sessions = 2048
  }
 Module: Linked to sub-module rlm_eap_md5
 Module: Instantiating eap-md5
 Module: Linked to sub-module rlm_eap_leap
 Module: Instantiating eap-leap
 Module: Linked to sub-module rlm_eap_gtc
 Module: Instantiating eap-gtc
   gtc {
        challenge = "Password: "
        auth_type = "PAP"
   }
 Module: Linked to sub-module rlm_eap_tls
 Module: Instantiating eap-tls
   tls {
        rsa_key_exchange = no
        dh_key_exchange = yes
        rsa_key_length = 512
        dh_key_length = 512
        verify_depth = 0
        pem_file_type = yes
        private_key_file = "/etc/raddb/certs/server.pem"
        certificate_file = "/etc/raddb/certs/server.pem"
        CA_file = "/etc/raddb/certs/ca.pem"
        private_key_password = "whatever"
        dh_file = "/etc/raddb/certs/dh"
        random_file = "/etc/raddb/certs/random"
        fragment_size = 1024
        include_length = yes
        check_crl = no
        cipher_list = "DEFAULT"
        make_cert_command = "/etc/raddb/certs/bootstrap"
    cache {
        enable = no
        lifetime = 24
        max_entries = 255
    }
   }
 Module: Linked to sub-module rlm_eap_ttls
 Module: Instantiating eap-ttls
   ttls {
        default_eap_type = "md5"
        copy_request_to_tunnel = no
        use_tunneled_reply = no
        virtual_server = "inner-tunnel"
        include_length = yes
   }
 Module: Linked to sub-module rlm_eap_peap
 Module: Instantiating eap-peap
   peap {
        default_eap_type = "mschapv2"
        copy_request_to_tunnel = no
        use_tunneled_reply = no
        proxy_tunneled_request_as_eap = yes
        virtual_server = "inner-tunnel"
   }
 Module: Linked to sub-module rlm_eap_mschapv2
 Module: Instantiating eap-mschapv2
   mschapv2 {
        with_ntdomain_hack = no
   }
 Module: Checking authorize {...} for more modules to load
 Module: Linked to module rlm_realm
 Module: Instantiating suffix
  realm suffix {
        format = "suffix"
        delimiter = "@"
        ignore_default = no
        ignore_null = no
  }
 Module: Linked to module rlm_files
 Module: Instantiating files
  files {
        usersfile = "/etc/raddb/users"
        acctusersfile = "/etc/raddb/acct_users"
        preproxy_usersfile = "/etc/raddb/preproxy_users"
        compat = "no"
  }
 Module: Checking session {...} for more modules to load
 Module: Linked to module rlm_radutmp
 Module: Instantiating radutmp
  radutmp {
        filename = "/var/log/radius/radutmp"
        username = "%{User-Name}"
        case_sensitive = yes
        check_with_nas = yes
        perm = 384
        callerid = yes
  }
 Module: Checking post-proxy {...} for more modules to load
 Module: Checking post-auth {...} for more modules to load
 Module: Linked to module rlm_attr_filter
 Module: Instantiating attr_filter.access_reject
  attr_filter attr_filter.access_reject {
        attrsfile = "/etc/raddb/attrs.access_reject"
        key = "%{User-Name}"
  }
 } # modules
} # server
server {
 modules {
 Module: Checking authenticate {...} for more modules to load
 Module: Checking authorize {...} for more modules to load
 Module: Linked to module rlm_preprocess
 Module: Instantiating preprocess
  preprocess {
        huntgroups = "/etc/raddb/huntgroups"
        hints = "/etc/raddb/hints"
        with_ascend_hack = no
        ascend_channels_per_line = 23
        with_ntdomain_hack = no
        with_specialix_jetstream_hack = no
        with_cisco_vsa_hack = no
        with_alvarion_vsa_hack = no
  }
 Module: Checking preacct {...} for more modules to load
 Module: Linked to module rlm_acct_unique
 Module: Instantiating acct_unique
  acct_unique {
        key = "User-Name, Acct-Session-Id, NAS-IP-Address, Client-IP-Address, NAS-Port"
  }
 Module: Checking accounting {...} for more modules to load
 Module: Linked to module rlm_detail
 Module: Instantiating detail
  detail {
        detailfile = "/var/log/radius/radacct/%{Client-IP-Address}/detail-%Y%m%d"
        header = "%t"
        detailperm = 384
        dirperm = 493
        locking = no
        log_packet_header = no
  }
 Module: Instantiating attr_filter.accounting_response
  attr_filter attr_filter.accounting_response {
        attrsfile = "/etc/raddb/attrs.accounting_response"
        key = "%{User-Name}"
  }
 Module: Checking session {...} for more modules to load
 Module: Checking post-proxy {...} for more modules to load
 Module: Checking post-auth {...} for more modules to load
 } # modules
} # server
radiusd: #### Opening IP addresses and Ports ####
listen {
        type = "auth"
        ipaddr = *
        port = 0
}
listen {
        type = "acct"
        ipaddr = *
        port = 0
}
listen {
        type = "control"
 listen {
        socket = "/var/run/radiusd/radiusd.sock"
 }
}
Listening on authentication address * port 1812
Listening on accounting address * port 1813
Listening on command file /var/run/radiusd/radiusd.sock
Listening on proxy address * port 1814
Ready to process requests.</pre>
<p>ตัวอย่างการรัน radtest และ ข้อความในหน้าจอโหมด debug ที่แสดง</p>
<pre>[root@fc11-64a raddb]# <strong>radtest user1 password1 127.0.0.1 1 testing123
</strong>Sending Access-Request of id 118 to 127.0.0.1 port 1812
        User-Name = "user1"
        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=118, length=34
        Reply-Message = "Hello, user1"</pre>
<p>หน้าจอโหมด debug ที่แสดง พร้อมเน้นข้อความที่เกี่ยวข้องกับการทำงานของ radiusd เมื่อได้รับการ request จากการรันคำสั่ง radtest แบบคร่าวๆ</p>
<pre>rad_recv: <span style="color: #0000ff;">Access-Request </span>packet from host 127.0.0.1 port 53435, id=118, length=57
<span style="color: #0000ff;">        User-Name = "user1"
</span><span style="color: #0000ff;">        User-Password = "password1"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 1
</span>+- entering group authorize {...}
++[preprocess] returns ok
++[chap] returns noop
++[mschap] returns noop
[suffix] <span style="color: #0000ff;">No '@' in User-Name = "user1", looking up realm NULL
</span>[suffix] No such realm "NULL"
++[suffix] returns noop
[eap] <span style="color: #0000ff;">No EAP-Message, not doing EAP
</span>++[eap] returns noop
++[unix] returns notfound
[files] <span style="color: #0000ff;">users: Matched entry user1 at line 203
</span>[files]         <span style="color: #0000ff;">expand: Hello, %{User-Name} -&gt; Hello, user1
</span>++[files] <span style="color: #0000ff;">returns ok
</span>++[expiration] returns noop
++[logintime] returns noop
++[pap] returns updated
Found Auth-Type = PAP
+- entering group PAP {...}
[pap] login attempt with password "password1"
[pap] <span style="color: #0000ff;">Using clear text password "password1"
</span>[pap] <span style="color: #0000ff;">User authenticated successfully
</span>++[pap] <span style="color: #0000ff;">returns ok
</span>+- entering group post-auth {...}
++[exec] returns noop
<span style="color: #0000ff;">Sending Access-Accept of id 118 to 127.0.0.1 port 53435
        Reply-Message = "Hello, user1"
</span>Finished request 0.
Going to the next request
Waking up in 4.9 seconds.
Cleaning up request 0 ID 118 with timestamp +58
Ready to process requests.</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://freeradius.org/" target="_blank">FreeRADIUS: The world&#8217;s most popular RADIUS Server</a></li>
<li><a href="http://mirrors.kernel.org/fedora/updates/11/x86_64/" target="_blank">Fedora 11 x86_64 updates</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/11/basic_install_freeradius/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>คอนฟิกเซอร์วิส nscd</title>
		<link>http://spalinux.com/2008/11/configure_nscd</link>
		<comments>http://spalinux.com/2008/11/configure_nscd#comments</comments>
		<pubDate>Fri, 28 Nov 2008 09:13:12 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Directory Server]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[cache]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=348</guid>
		<description><![CDATA[ในกรณีที่คอนฟิกให้ลีนุกซ์ตรวจสอบ user, group (authenticate) จาก LDAP Server ทุกครั้งที่มีการอ้างอิง เช่นการสร้างไฟล์ หรือแสดงรายชื่อไฟล์ด้วยคำสั่ง ls ของ user หรืออื่นๆ ที่เกี่ยวข้องกับ user, group เครื่องจะต้องมีการสอบถามจาก LDAP ทุกครั้ง ทำให้บางครั้งอาจเพิ่มโหลดมากเกินไปบนตัว LDAP Server เพื่อเพิ่มประสิทธิภาพในการตรวจสอบ user, group จาก LDAP แนะนำให้รันเซอร์วิส nscd (name service cache daemon) บนเครื่อง โดยโปรแกรมนี้จะทำหน้าที่เก็บข้อมูล cache ไว้บนเครื่องตัวเอง ถ้าถามซ้ำกับข้อมูลเดิมที่มีอยู่ใน cache แล้ว ภายในระยะเวลาที่กำหนดไว้ (time to live) จะไม่มีการส่งไปถาม LDAP Server อีก ข้อเสียของการรันเซอร์วิส nscd อย่างหนึ่งคือ เรื่องการตั้งค่าเวลา (time to [...]]]></description>
			<content:encoded><![CDATA[<p>ในกรณีที่คอนฟิกให้ลีนุกซ์ตรวจสอบ user, group (authenticate) จาก LDAP Server ทุกครั้งที่มีการอ้างอิง เช่นการสร้างไฟล์ หรือแสดงรายชื่อไฟล์ด้วยคำสั่ง ls ของ user หรืออื่นๆ ที่เกี่ยวข้องกับ user, group เครื่องจะต้องมีการสอบถามจาก LDAP ทุกครั้ง ทำให้บางครั้งอาจเพิ่มโหลดมากเกินไปบนตัว LDAP Server</p>
<p>เพื่อเพิ่มประสิทธิภาพในการตรวจสอบ user, group จาก LDAP แนะนำให้รันเซอร์วิส nscd (name service cache daemon) บนเครื่อง โดยโปรแกรมนี้จะทำหน้าที่เก็บข้อมูล cache ไว้บนเครื่องตัวเอง ถ้าถามซ้ำกับข้อมูลเดิมที่มีอยู่ใน cache แล้ว ภายในระยะเวลาที่กำหนดไว้ (time to live) จะไม่มีการส่งไปถาม LDAP Server อีก</p>
<p>ข้อเสียของการรันเซอร์วิส nscd อย่างหนึ่งคือ เรื่องการตั้งค่าเวลา (time to live) ทำให้บางครั้งอาจไม่ได้ข้อมูลที่ล่าสุด เช่นดีฟอลต์เวลาที่ cache ไว้สำหรับการเก็บข้อมูลของ user คือ 600 วินาที สำหรับการค้นหาข้อมูลที่สำเร็จ (positive-time-to-live) ถ้ามีการเปลี่ยนแปลงข้อมูลของ user บน LDAP Server จะต้องรอจนเวลานี้ผ่านไป  ข้อมูล cache ใน nscd ถึงจะปรับปรุงเป็นข้อมูลใหม่</p>
<p><span id="more-348"></span></p>
<h4>ปรับปรุงเวอร์ชั่น nscd</h4>
<p>ใช้คำสั่ง rpm เพื่อตรวจสอบเวอร์ชั่นของ nscd ที่ติดตั้งอยู่</p>
<pre>[root@ldap-client ~]# <strong>rpm -q nscd</strong>
nscd-2.8-3.i386</pre>
<p>คำแนะนำ ก่อนที่จะรันเซอร์วิส nscd แนะนำให้ปรับปรุงเป็นเวอร์ชั่นล่าสุด เช่น Fedora 9 เวอร์ชั่นล่าสุดที่เขียนบทความนี้คือ nscd-2.8-8</p>
<pre>[root@ldap-client ~]# <strong>rpm -Uvh nscd-2.8-8.i386.rpm
</strong>Preparing...                ########################################### [100%]
   1:nscd                   ########################################### [100%]</pre>
<h4>คอนฟิกไฟล์ /etc/nscd.conf</h4>
<p>ไฟล์คอนฟิกจากการติดตั้ง nscd จะเก็บ cache ของ passwd, group, hosts, services ในที่นี้เราจะเปลี่ยนคอนฟิกเพื่อให้เก็บ cache เฉพาะ passwd, group จาก LDAP</p>
<pre>[root@ldap-client ~]# <strong>cat /etc/nscd.conf
</strong>#
# /etc/nscd.conf
#
server-user             nscd
debug-level             0
paranoia                no</pre>
<pre>enable-cache            passwd          yes
positive-time-to-live   passwd          600
negative-time-to-live   passwd          20
suggested-size          passwd          211
check-files             passwd          yes
persistent              passwd          yes
shared                  passwd          yes
max-db-size             passwd          33554432
auto-propagate          passwd          yes</pre>
<pre>enable-cache            group           yes
positive-time-to-live   group           3600
negative-time-to-live   group           60
suggested-size          group           211
check-files             group           yes
persistent              group           yes
shared                  group           yes
max-db-size             group           33554432
auto-propagate          group           yes</pre>
<pre>enable-cache            hosts           <strong>no</strong>
enable-cache            services        <strong>no</strong></pre>
<p><strong>คำแนะนำการคอนฟิกไฟล์ nscd.conf</strong></p>
<ul>
<li>ดีฟอลต์คอนฟิกจากการติดตั้ง จะเป็บ cache ของ user (passwd) เป็นเวลา 600 วินาที สำหรับข้อมูลที่ค้นหาได้สำเร็จ (positive-time-to-live) แต่จะเก็บ cache ของ user ที่ค้นหาไม่สำเร็จ (ไม่มีข้อมูลใน LDAP) เป็นเวลา 20 วินาที</li>
<li>ดีฟอลต์คอนฟิกจากการติดตั้ง จะเป็บ cache ของ group เป็นเวลา 3600 วินาที สำหรับข้อมูลที่ค้นหาได้สำเร็จ (positive-time-to-live) แต่จะเก็บ cache ของ group ที่ค้นหาไม่สำเร็จ (ไม่มีข้อมูลใน LDAP) เป็นเวลา 60 วินาที</li>
<li>ต้องรอเวลา time-to-live เหล่านี้หมดไป จนกว่า nscd จะทำการตรวจสอบข้อมูลจาก LDAP ใหม่อีกครั้ง ก่อนการใช้งานจริงแนะนำให้ทดลองปรับค่าแล้วดูผลลัพธ์ที่ได้</li>
</ul>
<h4>รันเซอร์วิส nscd</h4>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส nscd</p>
<pre>[root@fc9-k2 ~]# <strong>service nscd start</strong>
Starting nscd:                                             [  OK  ]</pre>
<p>ข้อมูล cache ของ nscd จะถูกเก็บไว้ใน /var/db/nscd/</p>
<pre>[root@fc9-k2 ~]# <strong>ls -l /var/db/nscd/
</strong>total 432
-rw------- 1 root root 217016 2008-11-28 15:39 group
-rw------- 1 root root 217016 2008-11-28 15:39 passwd</pre>
<h4>ทดสอบ nscd cache</h4>
<p>ใช้คำสั่ง time เพื่อเปรียบเทียบความเร็ว ระหว่างการดึงข้อมูล user จาก LDAP ในครั้งแรก และครั้งที่สอง ดึงข้อมูลจาก cache ของ nscd</p>
<pre>[root@fc9-k2 ~]# <strong>time id user01</strong>
uid=1011(user01) gid=513(Domain Users) groups=513(Domain Users)</pre>
<pre>real    0m0.046s
user    0m0.000s
sys     0m0.007s</pre>
<pre>[root@fc9-k2 ~]# <strong>time id user01</strong>
uid=1011(user01) gid=513(Domain Users) groups=513(Domain Users)</pre>
<pre>real    0m0.007s
user    0m0.000s
sys     0m0.005s</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/10/add_user_into_openldap">เพิ่มบัญชีผู้ใช้งานเข้าไปใน OpenLDAP</a> </li>
<li><a href="http://spalinux.com/2008/07/authenticate_user_on_fedora_directory_server">คอนฟิกให้ authenticate จาก Fedora Directory Server</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/11/configure_nscd/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ไฟล์คอนฟิก openldap สำหรับ smbldap-tools</title>
		<link>http://spalinux.com/2008/11/openldap_configuration_for_smbldap-tools</link>
		<comments>http://spalinux.com/2008/11/openldap_configuration_for_smbldap-tools#comments</comments>
		<pubDate>Thu, 27 Nov 2008 16:25:07 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Directory Server]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[Samba]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=334</guid>
		<description><![CDATA[ไฟล์คอนฟิก /etc/openldap/slapd.conf สำหรับ คอนฟิก Samba เป็น Domain Controller โดยปรับปรุงเพิ่มเติมคุณสมบัติดังนี้ กำหนดคีย์ (index) ที่ใช้ในการค้นหาข้อมูล อนุญาตให้ผู้ใช้สามารถเปลี่ยน password โดยใช้คำสั่ง smbldap-passwd ด้วยตัวเองได้ ไม่ต้องใช้ rootdn ซ่อนรหัสผ่าน (password) ไม่ให้สามารถอ่านได้โดยตรง แต่ใช้ในการตรวจสอบสิทธิ (authenticate) ได้ # ------------------------ # /etc/openldap/slapd.conf # ------------------------ include     /etc/openldap/schema/corba.schema include     /etc/openldap/schema/core.schema include     /etc/openldap/schema/cosine.schema include     /etc/openldap/schema/duaconf.schema include     /etc/openldap/schema/dyngroup.schema include     /etc/openldap/schema/inetorgperson.schema include     /etc/openldap/schema/java.schema include     /etc/openldap/schema/misc.schema include     /etc/openldap/schema/nis.schema include     /etc/openldap/schema/openldap.schema include     /etc/openldap/schema/ppolicy.schema include     /etc/openldap/schema/collective.schema # [...]]]></description>
			<content:encoded><![CDATA[<p>ไฟล์คอนฟิก /etc/openldap/slapd.conf สำหรับ <a href="http://spalinux.com/2008/10/configure_samba_domain_controller">คอนฟิก Samba เป็น Domain Controller</a> โดยปรับปรุงเพิ่มเติมคุณสมบัติดังนี้</p>
<ul>
<li>กำหนดคีย์ (index) ที่ใช้ในการค้นหาข้อมูล</li>
<li>อนุญาตให้ผู้ใช้สามารถเปลี่ยน password โดยใช้คำสั่ง smbldap-passwd ด้วยตัวเองได้ ไม่ต้องใช้ rootdn</li>
<li>
<pre>ซ่อนรหัสผ่าน (password) ไม่ให้สามารถอ่านได้โดยตรง แต่ใช้ในการตรวจสอบสิทธิ (authenticate) ได้</pre>
</li>
</ul>
<p><span id="more-334"></span></p>
<pre># ------------------------
# /etc/openldap/slapd.conf
# ------------------------
include     /etc/openldap/schema/corba.schema
include     /etc/openldap/schema/core.schema
include     /etc/openldap/schema/cosine.schema
include     /etc/openldap/schema/duaconf.schema
include     /etc/openldap/schema/dyngroup.schema
include     /etc/openldap/schema/inetorgperson.schema
include     /etc/openldap/schema/java.schema
include     /etc/openldap/schema/misc.schema
include     /etc/openldap/schema/nis.schema
include     /etc/openldap/schema/openldap.schema
include     /etc/openldap/schema/ppolicy.schema
include     /etc/openldap/schema/collective.schema</pre>
<pre># Samba Schema
include     /etc/openldap/schema/samba.schema</pre>
<pre># Allow LDAPv2 client connections.  This is NOT the default.
allow bind_v2</pre>
<pre>pidfile     /var/run/openldap/slapd.pid
argsfile    /var/run/openldap/slapd.args</pre>
<pre># Enable Monitoring
database monitor</pre>
<pre># ldbm and/or bdb database definitions
database    bdb
suffix      "dc=test-ldap,dc=com"
rootdn      "uid=root,ou=People,dc=test-ldap,dc=com"
rootpw      {SSHA}xxx
directory   /var/lib/ldap</pre>
<pre># Indices to maintain for this database
index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub
index uniqueMember                      eq</pre>
<pre># required to support pdb_getsambapwrid()
index displayName                       pres,sub,eq
index sambaSID                          eq
index sambaPrimaryGroupSID              eq
index sambaDomainName                   eq
index sambaSIDList                      eq
index sambaGroupType                    eq
index default                           sub</pre>
<pre># users can authenticate and change their password
# hide password fields
access to attrs=userPassword,sambaNTPassword,sambaLMPassword,sambaPwdMustChange,sambaPwdLastSet
      by self write
      by anonymous auth
      by * none</pre>
<pre>access to attrs=shadowLastChange,shadowMax
      by self write
      by * read</pre>
<pre># all others attributes are readable to everybody
access to *
      by * read</pre>
<pre># loglevel stats stats2</pre>
<pre># EOF.</pre>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/11/openldap_configuration_for_smbldap-tools/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก Samba เป็น Domain Controller</title>
		<link>http://spalinux.com/2008/10/configure_samba_domain_controller</link>
		<comments>http://spalinux.com/2008/10/configure_samba_domain_controller#comments</comments>
		<pubDate>Sat, 18 Oct 2008 11:21:54 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[File Sharing]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[Samba]]></category>
		<category><![CDATA[domain controller]]></category>
		<category><![CDATA[smbldap-tools]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=284</guid>
		<description><![CDATA[จากบทความ ติดตั้ง smbldap-tools บน Fedora 9 นั้นเป็นการคอนฟิกให้ Samba ทำหน้าที่เป็น file sharing อย่างเดียว โดยผู้ใช้งานสามารถ map drive เข้ามาแล้ว authenticate จาก LDAP ได้ ในบทความนี้จะคอนฟิกเพิ่มเติมเพื่อให้ Samba ทำหน้าที่เป็น Domain Controller ของ Windows client ได้ แก้ไขไฟล์ /etc/samba/smb.conf ต้องแก้ไขไฟล์ smb.conf เพิ่มเติมโดยในที่นี้จะแสดงคอนฟิกทั้งหมดของไฟล์นี้เลย เพื่อคอนฟิกให้ Samba ทำหน้าที่เป็น Domain Controller [global] workgroup = SMBLDAP server string = Samba Server Version %v passdb backend = ldapsam:ldap://127.0.0.1/ passwd [...]]]></description>
			<content:encoded><![CDATA[<p>จากบทความ <a href="http://spalinux.com/2008/10/install_smbldap-tools_on_fedora_9">ติดตั้ง smbldap-tools บน Fedora 9</a><a href="http://spalinux.com/wp-content/uploads/2008/10/windows_join_domain.png"></a> นั้นเป็นการคอนฟิกให้ Samba ทำหน้าที่เป็น file sharing อย่างเดียว โดยผู้ใช้งานสามารถ map drive เข้ามาแล้ว authenticate จาก LDAP ได้</p>
<p>ในบทความนี้จะคอนฟิกเพิ่มเติมเพื่อให้ Samba ทำหน้าที่เป็น Domain Controller ของ Windows client ได้</p>
<p><span id="more-284"></span></p>
<h4>แก้ไขไฟล์ /etc/samba/smb.conf</h4>
<p>ต้องแก้ไขไฟล์ smb.conf เพิ่มเติมโดยในที่นี้จะแสดงคอนฟิกทั้งหมดของไฟล์นี้เลย เพื่อคอนฟิกให้ Samba ทำหน้าที่เป็น Domain Controller</p>
<pre>[global]
 workgroup = SMBLDAP
 server string = Samba Server Version %v</pre>
<pre> passdb backend = ldapsam:ldap://127.0.0.1/
 passwd program = /usr/sbin/smbldap-passwd -u "%u"
 passwd chat = "Changing *\nNew password*" %n\n "*Retype new password*" %n\n"
 unix password sync = Yes
 log file = /var/log/samba/log.%U
 max log size = 50
 time server = Yes
 socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192</pre>
<pre> add user script = /usr/sbin/smbldap-useradd -m "%u"
 delete user script = /usr/sbin/smbldap-userdel "%u"
 add group script = /usr/sbin/smbldap-groupadd -p "%g"
 delete group script = /usr/sbin/smbldap-groupdel "%g"
 add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
 delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
 set primary group script = /usr/sbin/smbldap-usermod -g '%g' '%u'
 add machine script = /usr/sbin/smbldap-useradd -t 0 -w "%u"</pre>
<pre> logon script = logon.bat
 logon path = \\%L\profiles\%u
 logon drive = H:
 domain logons = Yes
 os level = 65
 preferred master = Yes
 domain master = Yes
 wins support = Yes</pre>
<pre> ldap admin dn = uid=root,ou=People,dc=test-ldap,dc=com
 ldap group suffix = ou=Group
 ldap idmap suffix = ou=Idmap
 ldap machine suffix = ou=Computers
 ldap suffix = dc=test-ldap,dc=com
 ldap user suffix = ou=People
 cups options = raw</pre>
<pre>[homes]
 comment = Home Directories
 read only = No
 browseable = No</pre>
<pre>[profiles]
 path = /home/profiles
 read only = No
 guest ok = Yes
 browseable = No</pre>
<p>คำแนะนำ รันคำสั่ง testparm ทุกครั้งเพื่อตรวจสอบความถูกต้องของคอนฟิกไฟล์ หลังการแก้ไขไฟล์ /etc/samba/smb.conf</p>
<h4>สร้างไดเร็คทอรีสำหรับเก็บ profiles ของ user</h4>
<p>เพื่อให้ user สามารถล็อกอินจาก Windows หลายๆ เครื่องแล้วมี profiles เหมือนกัน เช่น desktop ต้องสร้างไดเร็คทอรี่บนลีนุกซ์ที่รัน Samba สำหรับเก็บ profiles ของ user</p>
<p>ตัวอย่างการสร้างไดเร็คทอรี สำหรับเก็บ profiles ของ user</p>
<pre>[root@fc9-min ~]# <strong>cd /home
</strong>[root@fc9-min home]# <strong>mkdir profiles
</strong>[root@fc9-min home]# <strong>chgrp "Domain Users" prof</strong>iles
[root@fc9-min home]# <strong>chmod 770 profil</strong>es
[root@fc9-min home]# <strong>ls -ld profiles
</strong>drwxrwx--- 2 root Domain Users 4096 2008-10-19 00:27 profiles</pre>
<h4>รันเซอร์วิส Samba</h4>
<p>เพื่อให้ Samba ทำหน้าที่เป็น Domain Controller ได้นั้น จำเป็นต้องรัน 2 เซอร์วิสคือ smb และ nmb ตามตัวอย่าง</p>
<pre>[root@fc9-min ~]# <strong>service smb start
</strong>Starting SMB services:                                     [  OK  ]</pre>
<pre>[root@fc9-min ~]# <strong>service nmb start</strong>
Starting NMB services:                                     [  OK  ]</pre>
<h4>คอนฟิก Windows ให้ join Domain</h4>
<p>ล็อกอินเป็น Administrator บนเครื่องไคลเอนต์ Windows ที่จะ join Domain คลิ้กขวาที่ My Computer แล้วเลือก Properties คลิ้กที่ Computer Name แล้วกดปุ่ม Change ใส่ชื่อ Domain ที่ต้องการ join ในที่นี้คือ SMBLDAP</p>
<p>หน้าจอ &#8220;Computer Name Changes&#8221; จะให้ใส่ User Name และ Password ที่จะใช้ join domain ให้ใส่ User Name เป็น root และใส่ password ตามที่ระบุใน rootpw</p>
<p><img title="Windows join domain" src="http://spalinux.com/wp-content/uploads/2008/10/windows_join_domain.png" alt=""/ border="1"></p>
<p>ถ้าถูกต้องจะมีหน้าจอขึ้นข้อความ &#8220;Welcome to the SMBLDAP domain.&#8221; กดปุ่ม Ok แล้วก็รีสตาร์ตเครื่อง</p>
<p><img title="Welcome to the SMBLDAP domain" src="http://spalinux.com/wp-content/uploads/2008/10/welcome_to_the_smbldap_domain.png" alt=""/ border="1"></p>
<p>หลังจากบู๊ตเครื่องเสร็จ หน้าจอ Log On to Windows จะสามารถเลือก Log on to เป็น SMBLDAP ได้ ใส่ user ที่เพิ่มจากคำสั่ง smbldap-useradd ในตัวอย่างคือ user01</p>
<p><img title="Windows Log On" src="http://spalinux.com/wp-content/uploads/2008/10/windows_log_on.png" alt="" /></p>
<p>เมื่อล๊อกออก (Log Off) จาก user01 จะมีการเก็บ profiles ของ user เข้าไปในไดเร็คทอรี บนลีนุกซ์ที่ตั้งไว้ด้วย</p>
<p>ตัวอย่างไฟล์ profiles ที่ถูกสร้างขึ้น ของ user01</p>
<pre>[root@fc9-min ~]# <strong>ls -l /home/profiles/user01/
</strong>total 568
drwx--x--x+ 4 user01 Domain Users   4096 2008-10-18 17:48 Application Data
drwx--x--x+ 2 user01 Domain Users   4096 2008-05-03 16:20 Cookies
drwx------+ 2 user01 Domain Users   4096 2008-05-03 23:12 Desktop
drwx--x--x+ 3 user01 Domain Users   4096 2008-10-18 17:49 Favorites
drwx--x--x+ 4 user01 Domain Users   4096 2008-10-18 17:49 My Documents
drwx--x--x+ 2 user01 Domain Users   4096 2008-05-03 23:12 NetHood
-rwx------  1 user01 Domain Users 524288 2008-10-18 17:54 NTUSER.DAT
-rwx------  1 user01 Domain Users   1024 2008-10-18 17:54 NTUSER.DAT.LOG
-rw-------  1 user01 Domain Users    268 2008-10-19 00:55 ntuser.ini
drwx--x--x+ 2 user01 Domain Users   4096 2008-05-03 23:12 PrintHood
drwx--x--x+ 2 user01 Domain Users   4096 2008-10-18 17:49 Recent
drwx--x--x+ 2 user01 Domain Users   4096 2008-10-18 17:48 SendTo
drwx--x--x+ 3 user01 Domain Users   4096 2008-05-03 23:12 Start Menu
drwx--x--x+ 2 user01 Domain Users   4096 2008-05-03 16:17 Templates</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/10/install_smbldap-tools_on_fedora_9">ติดตั้ง smbldap-tools บน Fedora 9</a></li>
<li><a href="http://spalinux.com/2008/10/using_smbldap-tools">การใช้งานคำสั่งของ smbldap-tools</a></li>
<li><a href="http://spalinux.com/2008/11/openldap_configuration_for_smbldap-tools">ไฟล์คอนฟิก openldap สำหรับ smbldap-tools</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/10/configure_samba_domain_controller/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>การใช้งานคำสั่งของ smbldap-tools</title>
		<link>http://spalinux.com/2008/10/using_smbldap-tools</link>
		<comments>http://spalinux.com/2008/10/using_smbldap-tools#comments</comments>
		<pubDate>Sat, 18 Oct 2008 10:11:53 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Directory Server]]></category>
		<category><![CDATA[File Sharing]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[Samba]]></category>
		<category><![CDATA[smbldap-tools]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=271</guid>
		<description><![CDATA[ในบทความนี้จะกล่าวถึงการใช้งานโปรแกรม smbldap-tools (เวอร์ชั่น 0.9.5) สำหรับเพิ่ม แก้ไข ลบข้อมูลของ user หรือ group ที่อยู่ใน LDAP เพื่อใช้งานร่วมกับ Samba หมายเหตุ ทุกคำสั่งของ smbldap-tools สามารถที่จะดูวิธีการใช้งานโดยย่อได้ จากการรันคำสั่งที่ต้องการแล้วต่อท้ายด้วยออปชั่น &#8216;-h&#8217; หรือ &#8216;-?&#8217; หรือไม่ก็อ่านรายละเอียดการใช้งานได้จาก man page ของแต่ละคำสั่ง smbldap-useradd เพิ่ม user คำสั่ง smbldap-useradd ใช้เพิ่ม user เข้าไปใน LDAP ตัวอย่างการเพิ่ม user01 เข้าไปใน LDAP [root@fc9-min ~]# smbldap-useradd -a -m -P user01 Changing UNIX and samba passwords for user01 New password: [...]]]></description>
			<content:encoded><![CDATA[<p>ในบทความนี้จะกล่าวถึงการใช้งานโปรแกรม smbldap-tools (เวอร์ชั่น 0.9.5) สำหรับเพิ่ม แก้ไข ลบข้อมูลของ user หรือ group ที่อยู่ใน LDAP เพื่อใช้งานร่วมกับ Samba</p>
<p>หมายเหตุ ทุกคำสั่งของ smbldap-tools สามารถที่จะดูวิธีการใช้งานโดยย่อได้ จากการรันคำสั่งที่ต้องการแล้วต่อท้ายด้วยออปชั่น &#8216;-h&#8217; หรือ &#8216;-?&#8217; หรือไม่ก็อ่านรายละเอียดการใช้งานได้จาก man page ของแต่ละคำสั่ง</p>
<p><span id="more-271"></span></p>
<hr />
<h4>smbldap-useradd เพิ่ม user</h4>
<p>คำสั่ง smbldap-useradd ใช้เพิ่ม user เข้าไปใน LDAP</p>
<p>ตัวอย่างการเพิ่ม user01 เข้าไปใน LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-useradd -a -m -P user01
</strong>Changing UNIX and samba passwords for user01
New password:
Retype new password:</pre>
<p>ออปชั่นของคำสั่ง smbldap-useradd ที่ใช้ เพื่อให้ใช้งานร่วมกับ Samba ได้มีดังนี้</p>
<ul>
<li>-a    เพิ่มข้อมูล Samba ของ user</li>
<li>-m   สร้างไดเร็คทอรี่ Home ของ user ด้วย</li>
<li>-P    ให้เรียกคำสั่ง smbldap-passwd หลังจบคำสั่ง เพื่อตั้งรหัสให้ user</li>
</ul>
<p>หลังจากที่เพิ่ม user เข้าในระบบแล้ว สามารถใช้คำสั่ง id หรือ getent เพื่อตรวจสอบข้อมูลของ user ได้</p>
<pre>[root@fc9-min ~]# <strong>id user01</strong>
uid=1001(user01) gid=513(Domain Users) groups=513(Domain Users)</pre>
<pre>[root@fc9-min ~]# <strong>getent passwd user01</strong>
user01:x:1001:513:System User:/home/user01:/bin/bash</pre>
<hr />
<h4>smbldap-passwd เปลี่ยนรหัสผ่านของ user</h4>
<p>คำสั้ง smbldap-passwd ใช้เพื่อเปลี่ยนรหัสผ่านของ user ที่อยู่ใน LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-passwd user01</strong>
Changing UNIX and samba passwords for user01
New password:
Retype new password:</pre>
<hr />
<h4>smbldap-userlist แสดงรายชื่อ user</h4>
<p>คำสั่ง smbldap-userlist ใช้เพื่อแสดงรายชื่อ user ทั้งหมดที่อยู่ใน LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-userlist
</strong>uid  |username</pre>
<pre>   0 |root                 |
 999 |nobody               |
1001 |user01               |</pre>
<hr />
<h4>smbldap-usershow แสดงรายละเอียด user</h4>
<p>คำสั่ง smbldap-usershow ใช้เพื่อตรวจสอบข้อมูลทั้งหมดของ user ที่อยู่ใน LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-usershow user01</strong>
dn: uid=user01,ou=People,dc=test-ldap,dc=com
objectClass: top,person,organizationalPerson,inetOrgPerson,posixAccount,shadowAccount,sambaSamAccount
uid: user01
uidNumber: 1001
gidNumber: 513
homeDirectory: /home/user01
sambaLogonTime: 0
sambaLogoffTime: 2147483647
sambaKickoffTime: 2147483647
sambaPwdCanChange: 0
displayName: user01
sambaSID: S-1-5-21-3697236364-1357617849-1956783867-3002
sambaPrimaryGroupSID: S-1-5-21-3697236364-1357617849-1956783867-513
sambaProfilePath: \\fc9-min\profiles\user01
sambaHomePath: \\fc9-min\user01
sambaHomeDrive: H:
sambaLMPassword: C53C042BF139A7D9AAD3B435B51404EE
sambaAcctFlags: [U]
sambaNTPassword: 152E0323FE05645650DD50FD31C2FCDF
sambaPwdLastSet: 1224343354
sambaPwdMustChange: 1228231354
userPassword: {SSHA}d+ZTyu7BhUarCaM2Ifu9bk/RS0lkSi80
shadowLastChange: 14170
shadowMax: 45
gecos: System User,,,,
cn: System User
sn: User
givenName: System
loginShell: /bin/bash</pre>
<hr />
<h4>smbldap-userinfo แก้ไขข้อมูลเบื้องต้นของ user</h4>
<p>คำสั่ง smbldap-userinfo ใช้เพื่อแก้ไขข้อมูลเบื้องต้นของ user เช่น User Shell, Full Name ถ้าต้องการแก้ไขข้อมูลอื่นๆ ต้องใช้คำสั่ง smbldap-usermod</p>
<pre>[root@fc9-min ~]# <strong>smbldap-userinfo user01
</strong>Changing the user information for user01
Enter the new value, or press ENTER for the default
 User Shell [/bin/bash]:
 Full Name [System User]: <strong>User01 Full Name</strong>
 Room Number []:
 Work Phone []:
 Home Phone []:
 Other []:
LDAP updated</pre>
<p>ตรวจสอบ Full Name หลังการแก้ไขด้วยคำสั่ง getent</p>
<pre>[root@fc9-min ~]# <strong>getent passwd user01</strong>
user01:x:1001:513:User01 Full Name,,,,:/home/user01:/bin/bash</pre>
<hr />
<h4>smbldap-usermod แก้ไขข้อมูลของ user</h4>
<p>คำสั่ง smbldap-usermod ใช้เพื่อแก้ข้อมูลของ user ที่อยู่ใน LDAP โดยต้องระบุออปชั่นที่ต้องการแก้ไข</p>
<p>ตัวอย่างการใช้คำสั่ง smbldap-usermod เพื่อแก้ไข Home ของ user01</p>
<pre>[root@fc9-min ~]# <strong>smbldap-usermod -d /new-home/user01 user01</strong></pre>
<p>ตรวจสอบหลังการแก้ไข</p>
<pre>[root@fc9-min ~]# <strong>getent passwd user01
</strong>user01:x:1001:513:User01 Full Name,,,,:/new-home/user01:/bin/bash</pre>
<p>เปลี่ยนข้อมูลกลับ</p>
<pre>[root@fc9-min ~]# <strong>smbldap-usermod -d /home/user01 user01
</strong>[root@fc9-min ~]# <strong>getent passwd user01
</strong>user01:x:1001:513:User01 Full Name,,,,:/home/user01:/bin/bash</pre>
<hr />
<h4>smbldap-userdel ลบ user</h4>
<p>คำสั่ง smbldap-userdel ใช้เพื่อลบ user ออกจาก LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-userdel -r user02</strong></pre>
<hr />
<h4>smbldap-groupadd เพิ่ม group</h4>
<p>คำสั่ง smbldap-groupadd ใช้เพื่อเพิ่ม group ใหม่เข้าไปใน LDAP</p>
<p>ตัวอย่างการเพิ่ม newgroup เข้าไปใน LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupadd newgroup</strong></pre>
<hr />
<h4>smbldap-groupshow ดูข้อมูลของ group</h4>
<p>คำสั่ง smbldap-groupshow ใช้เพื่อดูข้อมูลรายละเอียดของ group ที่อยู่ใน LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupshow newgroup</strong>
dn: cn=newgroup,ou=Group,dc=test-ldap,dc=com
objectClass: top,posixGroup
cn: newgroup
gidNumber: 1000</pre>
<hr />
<h4>smbldap-groupmod แก้ไขข้อมูลของ group</h4>
<p>คำสั่ง smbldap-groupmod ใช้เพื่อแก้ไขข้อมูลของ group เช่น การเพิ่ม user เข้าไปอยู่ใน group</p>
<p>ตัวอย่างการเพิ่ม user01 เข้าไปอยู่ใน newgroup</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupmod -m user01 newgroup</strong>
adding user user01 to group newgroup</pre>
<pre>[root@fc9-min ~]# <strong>id user01
</strong>uid=1001(user01) gid=513(Domain Users) groups=513(Domain Users),1000(newgroup)</pre>
<p>ตัวอย่างการเพิ่มหลายๆ user เข้าไปใน newgroup</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupmod -m user02,user03,user04,user05 newgroup
</strong>adding user user02 to group newgroup
adding user user03 to group newgroup
adding user user04 to group newgroup
adding user user05 to group newgroup</pre>
<p>ตรวจสอบข้อมูลของ newgroup</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupshow newgroup
</strong>dn: cn=newgroup,ou=Group,dc=test-ldap,dc=com
objectClass: top,posixGroup
cn: newgroup
gidNumber: 1000
memberUid: user01,user02,user03,user04,user05</pre>
<p>ตัวอย่างการลบ user ออกจาก group</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupmod -x user01 newgroup</strong>
deleting user user01 from group newgroup</pre>
<pre>[root@fc9-min ~]# <strong>id user01
</strong>uid=1001(user01) gid=513(Domain Users) groups=513(Domain Users)</pre>
<hr />
<h4>smbldap-groupdel ลบ group</h4>
<p>คำสั่ง smbldap-groupdel ใช้เพื่อลบ group ออกจาก LDAP</p>
<p>ตัวอย่างการลบ newgroup ออกจาก LDAP</p>
<pre>[root@fc9-min ~]# <strong>smbldap-groupdel newgroup</strong></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li> <a href="http://spalinux.com/2008/10/install_smbldap-tools_on_fedora_9">ติดตั้ง smbldap-tools บน Fedora 9</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/10/using_smbldap-tools/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

