<?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; SSH</title>
	<atom:link href="http://spalinux.com/category/ssh/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Mon, 26 Jul 2010 09:51:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<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[SSH]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Solaris]]></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>เซ็ตฟอนต์ไทยใน PuTTY</title>
		<link>http://spalinux.com/2009/05/set_font_thai_in_putty</link>
		<comments>http://spalinux.com/2009/05/set_font_thai_in_putty#comments</comments>
		<pubDate>Sun, 31 May 2009 15:23:24 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[SSH]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[Thai]]></category>
		<category><![CDATA[putty]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=724</guid>
		<description><![CDATA[บทความนี้ขอเสนอวิธีการเซ็ตฟอนต์ไทยในโปรแกรม PuTTY เพื่อให้สามารถแสดงตัวอักษรภาษาไทยได้ถูกต้อง ทั้งการพิมพ์และการแสดงผล ซึ่งหลักการนี้สามารถนำไปใช้กับโปรแกรม Terminal Client อื่นๆ ได้ ตัวอย่างในบทความนี้ทดสอบโดยการใช้ PuTTY เปิด secure shell ไปที่ Fedora 10 เริ่มต้นทดสอบโดยการใช้คำสั่ง echo พิมพ์คำว่า &#8220;สวัสดี&#8221; ลงไปในโปรแกรม PuTTY  แต่หน้าจอแสดงผลเป็น &#8220;&#8230;..&#8221; ทั้งตอนที่เราพิมพ์ลงไป และแสดงผลลัพธ์ออกมา  เหตุผลประการแรกที่โปรแกรม PuTTY ไม่สามารถแสดงภาษาไทยได้ถูกต้องคือปัญหาเรื่อง encoding   เพราะว่าลีนุกซ์เวอร์ชั่นใหม่ๆ จะเซ็ต encoding เป็นแบบ &#8220;UTF-8&#8243; โดยดีฟอลต์ สามารถดูได้จากการรันคำสั่ง &#8220;locale&#8221;  ในที่นี้เป็น &#8221;en_US.UTF8&#8243;    แต่ในโปรแกรม PuTTY คอนฟิกดีฟอลต์จากการติดตั้ง จะเซ็ต encoding เป็น &#8220;ISO-8859-1&#8243;  ซึ่งสามารถดูได้จาก คลิ้กขวาที่รูปไอคอนด้านซ้ายบนของหน้าจอโปรแกรม PuTTY แล้วเลือกเมนู &#8220;Change Settings&#8221;  คลิ้กเลือก Category ที่ [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้ขอเสนอวิธีการเซ็ตฟอนต์ไทยในโปรแกรม PuTTY เพื่อให้สามารถแสดงตัวอักษรภาษาไทยได้ถูกต้อง ทั้งการพิมพ์และการแสดงผล ซึ่งหลักการนี้สามารถนำไปใช้กับโปรแกรม Terminal Client อื่นๆ ได้</p>
<p><span id="more-724"></span></p>
<p>ตัวอย่างในบทความนี้ทดสอบโดยการใช้ PuTTY เปิด secure shell ไปที่ Fedora 10</p>
<p>เริ่มต้นทดสอบโดยการใช้คำสั่ง echo พิมพ์คำว่า &#8220;สวัสดี&#8221; ลงไปในโปรแกรม PuTTY  แต่หน้าจอแสดงผลเป็น &#8220;&#8230;..&#8221; ทั้งตอนที่เราพิมพ์ลงไป และแสดงผลลัพธ์ออกมา</p>
<p><img class="alignnone size-full wp-image-727" title="Cannot display Thai" src="http://spalinux.com/wp-content/uploads/2009/05/01_cannot_display_thai.png" alt="Cannot display Thai" width="650" height="445" /></p>
<p> เหตุผลประการแรกที่โปรแกรม PuTTY ไม่สามารถแสดงภาษาไทยได้ถูกต้องคือปัญหาเรื่อง encoding   เพราะว่าลีนุกซ์เวอร์ชั่นใหม่ๆ จะเซ็ต encoding เป็นแบบ &#8220;UTF-8&#8243; โดยดีฟอลต์ สามารถดูได้จากการรันคำสั่ง &#8220;locale&#8221;  ในที่นี้เป็น &#8221;en_US.UTF8&#8243;</p>
<p><img class="alignnone size-full wp-image-728" title="Locale" src="http://spalinux.com/wp-content/uploads/2009/05/02_locale.png" alt="Locale" width="650" height="445" /> </p>
<p> แต่ในโปรแกรม PuTTY คอนฟิกดีฟอลต์จากการติดตั้ง จะเซ็ต encoding เป็น &#8220;ISO-8859-1&#8243;  ซึ่งสามารถดูได้จาก คลิ้กขวาที่รูปไอคอนด้านซ้ายบนของหน้าจอโปรแกรม PuTTY แล้วเลือกเมนู &#8220;Change Settings&#8221;</p>
<p><img class="alignnone size-full wp-image-729" title="Change settings" src="http://spalinux.com/wp-content/uploads/2009/05/03_change_settings.png" alt="Change settings" width="661" height="459" /></p>
<p> คลิ้กเลือก Category ที่ &#8220;Translation&#8221;  จะขึ้นคอนฟิกเกี่ยวกับเรื่อง encoding   ดูที่ &#8220;Received data assumed to be in which character set&#8221;  โดยดีฟอลต์จะเป็น &#8220;ISO-8859-1:1998 (Latin-1, West Europe)&#8221;</p>
<p><img class="alignnone size-full wp-image-730" title="Default Translation" src="http://spalinux.com/wp-content/uploads/2009/05/04_default_translation.png" alt="Default Translation" width="456" height="443" /></p>
<p> เปลี่ยนคอนฟิกให้เป็น &#8220;UTF-8&#8243;</p>
<p><img class="alignnone size-full wp-image-731" title="Change to UTF-8" src="http://spalinux.com/wp-content/uploads/2009/05/05_change_to_utf-8.png" alt="Change to UTF-8" width="469" height="534" /></p>
<p>ทดลองพิมพ์คำสั่ง echo แล้วตามด้วยตัวอักษรภาษาไทยคำว่า &#8220;สวัสดี&#8221; อีกครั้ง  ในที่นี้การแสดงผลก็ยังไม่ถูกต้องนัก คือไม่สามารถแสดงสระบนล่างได้ถูกต้อง </p>
<p> <img class="alignnone size-full wp-image-732" title="After UTF-8" src="http://spalinux.com/wp-content/uploads/2009/05/06_after_utf-8.png" alt="After UTF-8" width="650" height="445" /></p>
<p> ปัญหาเรื่องการไม่แสดงสระไม่ครบแบบนี้ สามารถแก้ไขใน PuTTY โดยต้องแก้ไข ฟอนต์ (Font settings) ที่ใช้   คลิ้กเลือก Category ที่ &#8220;Appearance&#8221; หน้าจอจะแสดงผลเกี่ยวกับ Font โดยดีฟอลต์จะใช้ &#8220;Courier New, 10-point&#8221;</p>
<p><img class="alignnone size-full wp-image-733" title="Default Appearance" src="http://spalinux.com/wp-content/uploads/2009/05/07_default_appearance.png" alt="Default Appearance" width="456" height="443" /></p>
<p>  กดที่ปุ่ม &#8220;Change&#8221; เพื่อเลือก Font ใหม่เป็น &#8220;Fixedsys, Regular, 9-point&#8221; แล้วกดปุ่ม [OK]</p>
<p><img class="alignnone size-full wp-image-734" title="Change to Fixedsys" src="http://spalinux.com/wp-content/uploads/2009/05/08_change_to_fixedsys.png" alt="Change to Fixedsys" width="608" height="575" /></p>
<p> หลังจากเปลี่ยนฟอนต์แล้ว การแสดงผลตัวอักษรภาษาไทยจะถูกต้อง ทดลองใช้คำสั่ง echo พิมพ์คำว่า &#8220;ขอบคุณครับ&#8221;</p>
<p><img class="alignnone size-full wp-image-735" title="After change font" src="http://spalinux.com/wp-content/uploads/2009/05/09_after_change_font.png" alt="After change font" width="650" height="421" /></p>
<p>  หลังจากคอนฟิกเรียบร้อยแล้ว ถ้าต้องการเซฟค่าคอนฟิกใหม่นี้ของ PuTTY สามารถทำได้โดยกดเลือก Category ที่ Session คลิ้กเลือก &#8220;Saved Sessions&#8221; ที่ &#8220;Default Settings&#8221; แล้วกดปุ่ม [Save]</p>
<p><img class="alignnone size-full wp-image-725" title="Save Default settings" src="http://spalinux.com/wp-content/uploads/2009/05/10_save_default_settings.png" alt="Save Default settings" width="456" height="443" /></p>
<h4> </h4>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank"><span style="color: #667755;">PuTTY: A Free Telnet/SSH Client</span></a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/05/set_font_thai_in_putty/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>แก้ปัญหาล็อกอิน Secure Shell ช้า</title>
		<link>http://spalinux.com/2009/02/solve_slow_login_secure_shell</link>
		<comments>http://spalinux.com/2009/02/solve_slow_login_secure_shell#comments</comments>
		<pubDate>Sat, 21 Feb 2009 09:52:05 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[SSH]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=465</guid>
		<description><![CDATA[เคยประสบปัญหาในการล็อกอินด้วย secure shell ไปยังเครื่องปลายทางช้าหรือไม่ กว่าที่จะขึ้นให้ใส่ password โดยที่เครื่องปลายทาง (secure shell server) ดูแล้วปกติไม่ได้ทำงานหนักอะไร โหลดของเครื่องก็เป็น 0.00 ตรวจสอบโหลดบนเครื่องปลายทาง ด้วยคำสั่ง uptime [root@ssh-server ~]# uptime  16:02:28 up  1:21,  1 user,  load average: 0.00, 0.00, 0.00 บทความนี้จะเสนอการแก้ไขคอนฟิกของ sshd ซึ่งทำหน้าที่เป็น secure shell server โดยตัวอย่างทดสอบ ssh จากเครื่องชื่อ ssh-client ไปยังเครื่องปลายทางชื่อ ssh-server (192.168.1.1) 1. ปิดการตรวจสอบสิทธิแบบ GSSAPI เริ่มต้นทดสอบใช้คำสั่ง ssh จากเครื่องไคลเอนต์ด้วยออปชั่น -v เพื่อดูรายละเอียดขั้นตอนในการล็อกอินด้วย secure shell ไปยังเครื่องปลายทาง ถ้าสังเกตดูหน้าจอจะค้างตรงบรรทัด ... [...]]]></description>
			<content:encoded><![CDATA[<p>เคยประสบปัญหาในการล็อกอินด้วย secure shell ไปยังเครื่องปลายทางช้าหรือไม่ กว่าที่จะขึ้นให้ใส่ password โดยที่เครื่องปลายทาง (secure shell server) ดูแล้วปกติไม่ได้ทำงานหนักอะไร โหลดของเครื่องก็เป็น 0.00</p>
<p>ตรวจสอบโหลดบนเครื่องปลายทาง ด้วยคำสั่ง uptime</p>
<pre>[root@ssh-server ~]# <strong>uptime</strong>
 16:02:28 up  1:21,  1 user,  load average: 0.00, 0.00, 0.00</pre>
<p>บทความนี้จะเสนอการแก้ไขคอนฟิกของ sshd ซึ่งทำหน้าที่เป็น secure shell server โดยตัวอย่างทดสอบ ssh จากเครื่องชื่อ ssh-client ไปยังเครื่องปลายทางชื่อ ssh-server (192.168.1.1)</p>
<p><span id="more-465"></span></p>
<h4>1. ปิดการตรวจสอบสิทธิแบบ GSSAPI</h4>
<p>เริ่มต้นทดสอบใช้คำสั่ง ssh จากเครื่องไคลเอนต์ด้วยออปชั่น -v เพื่อดูรายละเอียดขั้นตอนในการล็อกอินด้วย secure shell ไปยังเครื่องปลายทาง ถ้าสังเกตดูหน้าจอจะค้างตรงบรรทัด</p>
<pre>...
debug1: Next authentication method: gssapi-with-mic</pre>
<p>ช่วงที่หน้าจอค้าง จะเป็นขั้นตอนการตรวจสอบสิทธิ (user authentication) แบบ GSSAPI ซึ่งถ้าเราไม่ได้ใช้งาน หรือคอนฟิกไว้ สามารถเปลี่ยนคอนฟิกของ sshd เพื่อปิดการตรวจสอบสิทธิแบบนี้ออกไป</p>
<pre>[user1@ssh-client ~]$ <strong>ssh -v 192.168.1.1
</strong>OpenSSH_5.1p1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/user1/.ssh/identity type -1
debug1: identity file /home/user1/.ssh/id_rsa type -1
debug1: identity file /home/user1/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1
debug1: match: OpenSSH_5.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server-&gt;client aes128-cbc hmac-md5 none
debug1: kex: client-&gt;server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024&lt;1024&lt;8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.1.1' is known and matches the RSA host key.
debug1: Found key in /home/user1/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found</pre>
<pre>debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found</pre>
<pre>debug1: Unspecified GSS failure.  Minor code may provide more information</pre>
<pre>debug1: Next authentication method: publickey
debug1: Trying private key: /home/user1/.ssh/identity
debug1: Trying private key: /home/user1/.ssh/id_rsa
debug1: Trying private key: /home/user1/.ssh/id_dsa
debug1: Next authentication method: password
user1@192.168.1.1's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
[user1@ssh-server ~]$</pre>
<p>แก้ไขคอนฟิกของ ssh-server โดยแก้ออปชั่นของ GSSAPI ดังนี้</p>
<pre>[root@ssh-server ssh]# <strong>cat /etc/ssh/sshd_config
</strong>...
# GSSAPI options
<strong>GSSAPIAuthentication no
GSSAPICleanupCredentials no
</strong>...</pre>
<p>หลังจากแก้ไข ใช้คำสั่ง service เพื่อรีโหลด secure sshd ใหม่อีกครั้ง เพื่อให้คอนฟิกใหม่มีผล</p>
<pre>[root@ssh-server ssh]# <strong>service sshd restart
</strong>Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@ssh-server ssh]#</pre>
<p>ทดสอบการ ssh อีกครั้งหลังจากปิดคุณสมบัติ GSSAPI บนเซิร์ฟเวอร์ จะเห็นว่าเร็วขึ้นมาก ไม่มีบรรทัดที่เกี่ยวข้องกับ GSSAPI ขึ้นมาอีก</p>
<pre>[user1@ssh-client ~]$ <strong>ssh -v 192.168.1.1
</strong>OpenSSH_5.1p1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/user1/.ssh/identity type -1
debug1: identity file /home/user1/.ssh/id_rsa type -1
debug1: identity file /home/user1/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1
debug1: match: OpenSSH_5.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server-&gt;client aes128-cbc hmac-md5 none
debug1: kex: client-&gt;server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024&lt;1024&lt;8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.1.1' is known and matches the RSA host key.
debug1: Found key in /home/user1/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user1/.ssh/identity
debug1: Trying private key: /home/user1/.ssh/id_rsa
debug1: Trying private key: /home/user1/.ssh/id_dsa
debug1: Next authentication method: password
user1@192.168.1.1's password:
[user1@ssh-client ~]$</pre>
<pre> </pre>
<pre>
<h4>2. ปิดการตรวจสอบชื่อ hostname กับ DNS (reverse hostname lookup)</h4>

ดีฟอลต์คอนฟิกของ sshd ที่ติดตั้งกับ Fedora เมื่อมีการล็อกอินเข้ามา เซิร์ฟเวอร์จะพยายามแปลง IP Address ของไคลเอนต์ที่เข้ามาเป็นชื่อ hostname โดยไปถามจาก DNS Server (reverse hostname lookup)

ถ้าเครื่อง ssh-server ไม่สามารถติดต่อกับ DNS Server หรือ ไม่มีข้อมูล IP Address ของเครื่องไคลเอนต์อยู่ใน DNS Server ที่คอนฟิกไว้ การล็อกอินจะค้างไปซักพักตรงบรรทัด
<pre>...
debug1: SSH2_MSG_SERVICE_ACCEPT received</pre>
<p>ตัวอย่างการล็อกอิน</p>
<pre>[user1@ssh-client ~]$ <strong>ssh -v 192.168.1.1
</strong>OpenSSH_5.1p1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/user1/.ssh/identity type -1
debug1: identity file /home/user1/.ssh/id_rsa type -1
debug1: identity file /home/user1/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1
debug1: match: OpenSSH_5.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server-&gt;client aes128-cbc hmac-md5 none
debug1: kex: client-&gt;server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024&lt;1024&lt;8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.1.1' is known and matches the RSA host key.
debug1: Found key in /home/user1/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received</pre>
<p>สามารถแก้ไขปัญหานี้ด้วยการปิดคุณสมบัติการตรวจสอบชื่อ hostname จาก IP Address ของไคลเอนต์ โดยแก้ออปชั่นของ UseDNS ให้เป็นค่า no ดังนี้</p>
<pre>[root@ssh-server ssh]# <strong>cat /etc/ssh/sshd_config
</strong>...
<strong>UseDNS no
</strong>...</pre>
<p>หลังจากแก้ไข ใช้คำสั่ง service เพื่อรีโหลด sshd ใหม่อีกครั้ง เพื่อให้คอนฟิกใหม่มีผล</p>
<pre>[root@ssh-server ssh]# <strong>service sshd restart
</strong>Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@ssh-server ssh]#</pre>
</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/10/introduction_to_secure_shell_ssh">แนะนำการใช้งานโปรแกรม Secure Shell (SSH)</a></li>
<li>man sshd_config(5)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/02/solve_slow_login_secure_shell/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSH &#8211; Secure Shell ล็อกอินด้วย Public Key Authentication</title>
		<link>http://spalinux.com/2008/10/ssh_secure_shell_login_using_public_key_authentication</link>
		<comments>http://spalinux.com/2008/10/ssh_secure_shell_login_using_public_key_authentication#comments</comments>
		<pubDate>Thu, 09 Oct 2008 18:30:13 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Linux Shell]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[public key authentication]]></category>
		<category><![CDATA[secure shell]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=235</guid>
		<description><![CDATA[จากที่ได้ แนะนำการใช้งานโปรแกรม Secure Shell (SSH) เพื่อล็อกอินไปยังเครื่องอื่นนั้น โดยดีฟอลต์แล้วจะต้องใส่รหัสผ่าน (password) ก่อนที่จะล็อกเข้าไปยังเครื่องปลายทางได้ หรือรันคำสั่งบนเครื่องปลายทางได้ แต่ในบางครั้งการที่ต้องใส่รหัสผ่านทุกครั้งทำให้ไม่สะดวกในการใช้งาน ตัวอย่างเช่นต้องล็อกอินไปยังหลายๆ เครื่องอยู่เป็นประจำ หรือการเขียน Shell Script เพื่อล็อกอินไปยังเครื่องต่างๆ เพื่อรันคำสั่งที่ต้องการ   ในที่นี้จะแนะนำการล๊อกอินไปยังเครื่องปลายทางโดยไม่ต้องใส่รหัสผ่าน แต่อาศัยการล็อกด้วย Public Key Authentication การตรวจสอบสิทธิในการล็อกอินโดยใช้ Public Key Authentication ในตัวอย่างของบทความนี้จะคอนฟิกในระดับ user คือจะคอนฟิก user1 บนเครื่องไคลเอนต์ (Client) เพื่อจะล็อกอินไปเป็น user2 บนเซิร์ฟเวอร์ (Server) โดยไม่ต้องใส่รหัสผ่าน ขั้นตอนที่ต้องทำมีดังนี้ หมายเหตุ ตัวอย่างในบทความนี่ทดสอบบน Fedora 9 ซึ่งคอนฟิกดีฟอลต์จะอนุญาตให้สามารถล็อกอินแบบ Public Key Authentication ได้ หากคุณใช้ลีนุกซ์เวอร์ชั่นอื่นๆ ถ้าทำตามแล้วไม่ได้ ลองตรวจสอบไฟล์คอนฟิกของ ssh server ซึ่งอยู่ในไฟล์ /etc/ssh/sshd_config [...]]]></description>
			<content:encoded><![CDATA[<p>จากที่ได้ <a href="http://spalinux.com/2008/10/introduction_to_secure_shell_ssh" target="_self">แนะนำการใช้งานโปรแกรม Secure Shell (SSH)</a> เพื่อล็อกอินไปยังเครื่องอื่นนั้น โดยดีฟอลต์แล้วจะต้องใส่รหัสผ่าน (password) ก่อนที่จะล็อกเข้าไปยังเครื่องปลายทางได้ หรือรันคำสั่งบนเครื่องปลายทางได้</p>
<p>แต่ในบางครั้งการที่ต้องใส่รหัสผ่านทุกครั้งทำให้ไม่สะดวกในการใช้งาน ตัวอย่างเช่นต้องล็อกอินไปยังหลายๆ เครื่องอยู่เป็นประจำ หรือการเขียน Shell Script เพื่อล็อกอินไปยังเครื่องต่างๆ เพื่อรันคำสั่งที่ต้องการ   ในที่นี้จะแนะนำการล๊อกอินไปยังเครื่องปลายทางโดยไม่ต้องใส่รหัสผ่าน แต่อาศัยการล็อกด้วย Public Key Authentication</p>
<p><span id="more-235"></span></p>
<p>การตรวจสอบสิทธิในการล็อกอินโดยใช้ Public Key Authentication ในตัวอย่างของบทความนี้จะคอนฟิกในระดับ user คือจะคอนฟิก user1 บนเครื่องไคลเอนต์ (Client) เพื่อจะล็อกอินไปเป็น user2 บนเซิร์ฟเวอร์ (Server) โดยไม่ต้องใส่รหัสผ่าน ขั้นตอนที่ต้องทำมีดังนี้</p>
<p>หมายเหตุ ตัวอย่างในบทความนี่ทดสอบบน Fedora 9 ซึ่งคอนฟิกดีฟอลต์จะอนุญาตให้สามารถล็อกอินแบบ Public Key Authentication ได้ หากคุณใช้ลีนุกซ์เวอร์ชั่นอื่นๆ ถ้าทำตามแล้วไม่ได้ ลองตรวจสอบไฟล์คอนฟิกของ ssh server ซึ่งอยู่ในไฟล์ /etc/ssh/sshd_config โดยคอนฟิกที่ต้องเปิดไว้คือ PubkeyAuthentication และ AuthorizedKeysFile</p>
<h4>สร้าง Public/Private Key ของ user1 บนเครื่องไคลเอนต์</h4>
<p>ล๊อกอินเป็น user1 บนเครื่องไคลเอนต์แล้วใช้คำสั่ง ssh-keygen เพื่อสร้าง Public/Private Key</p>
<p>ตัวอย่างการใช้คำสั่ง ssh-keygen</p>
<pre>[user1@client ~]$ <strong>ssh-keygen
</strong>Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
fd:5c:11.......... user1@client</pre>
<p>สองไฟล์ที่ถูกสร้างจากการรันคำสั่ง ssh-keygen จะถูกเก็บไว้ในไดเร็คทอรี .ssh/ โดยจะมีไฟล์</p>
<ul>
<li><strong>id_rsa</strong> เป็นไฟล์ที่เก็บ Private Key ซี่งเป็นคีย์ที่เป็นความลับไม่แนะนำให้เปิดเผยไฟล์นี้ให้คนอื่นเห็น สังเกตได้จากสิทธิของไฟล์ (permission) จะเป็น 600</li>
<li><strong>id_rsa.pub</strong> เป็นไฟล์ที่เก็บ Public Key ซึ่งเป็นคีย์ที่สามารถเปิดเผยให้คนอื่นเห็นได้ แล้วใช้ในการเข้ารหัสข้อมูลเพื่อยืนยันว่าเป็นตัวเราจริงๆ โดยเราจะ copy ไฟล์นี้ไปยัง user2 บนเครื่องปลายทาง</li>
</ul>
<h4>ไฟล์ authorized_keys ของ user2 บนเครื่องเซิร์ฟเวอร์</h4>
<p>ขั้นตอนต่อไปคือ copy ไฟล์ Public Key ของ user1 จากเครื่องไคลเอนต์  ไปเก็บไว้ในไฟล์ authorized_keys ของ user2 บนเครื่องเซิร์ฟเวอร์ ซึ่งจะเป็นไฟล์ที่เก็บ Public Key ของ user ต่างๆ ที่มีสิทธิล๊อกอินมาเป็น user นี้โดยไม่ต้องใส่รหัส </p>
<p>วิธีการ copy ไฟล์  Public Key จากไคลเอนต์ไปยังเซิร์ฟเวอร์ สามารถทำได้โดยใช้คำสั่ง scp บนเครื่องไคลเอนต์</p>
<p>ตัวอย่างการ copy ไฟล์ จากเครื่องไคลเอนต์ไปยังเซิร์ฟเวอร์โดยใช้คำสั่ง scp</p>
<pre>[user1@client ~]$ <strong>scp .ssh/id_rsa.pub user2@server:
</strong>user2@server's password:
id_rsa.pub                              100%  394     0.4KB/s   00:00</pre>
<p>หมายเหตุ อย่าลืมเครื่องหมาย :  (colon) หลังคำว่า server เพื่อระบุว่าเป็นการ copy ระหว่างเครื่อง</p>
<p>ขั้นต่อไปล๊อกอินเป็น user2 บนเครื่องเซิร์ฟเวอร์ แล้วใช้คำสั่ง ls ดู จะเห็นไฟล์ที่ถูก copy มา ให้ใช้คำสั่ง cat เพื่อนำคีย์ในไฟล์นี้ไปต่อท้ายไฟล์ authorized_keys ของ user2</p>
<p>หมายเหตุ ต้องสร้างไดเร็คทอรี .ssh/ ของ user2 ไว้ก่อนที่จะสร้างหรือเพิ่มเติมไฟล์ authorized_keys ตามตัวอย่างด้านล้างนี้ได้</p>
<p><span style="color: #ff0000;">คำเตือน ระมัดระวังการใช้คำสั่ง cat เพื่อนำข้อมูลไปต่อท้ายไฟล์ต้องใช้เครื่องหมายมากกว่าสองอันติดกัน <strong>&gt;&gt;</strong>  </span></p>
<p>ตัวอย่างการสร้างไดเร็คทอรี .ssh/ และการเพิ่ม authorized_keys บนเซิร์ฟเวอร์</p>
<pre>[user2@server ~]$ <strong>ls -l
</strong>total 4
-rw-r--r-- 1 user2 users 394 2008-10-10 15:09 id_rsa.pub</pre>
<pre>[user2@server ~]$ <strong>mkdir .ssh</strong>
[user2@server ~]$ <strong>chmod 700 .ssh</strong>/</pre>
<pre>[user2@server ~]$ <strong>cat id_rsa.pub &gt;&gt; .ssh/authorized_keys</strong></pre>
<h4>ทดลองล็อกอินโดยใช้ Public Key Authentication</h4>
<p>ทดลองใช้ user1 บนเครื่องไคลเอนต์ไปยัง user2 บนเครื่องเซิร์ฟเวอร์ โดยรูปแบบการใช้งานยังเหมือนเดิมไม่เปลี่ยนแปลง จะเห็นว่าไม่ต้องใส่รหัสผ่าน (password) อีกต่อไปแล้ว</p>
<pre>[user1@client ~]$ <strong>ssh user2@server</strong>
[user2@server ~]$</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li>man sshd_config(5)</li>
<li><a href="http://spalinux.com/2008/10/introduction_to_secure_shell_ssh" target="_self">แนะนำการใช้งานโปรแกรม Secure Shell (SSH)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/10/ssh_secure_shell_login_using_public_key_authentication/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>แนะนำการใช้งานโปรแกรม Secure Shell (SSH)</title>
		<link>http://spalinux.com/2008/10/introduction_to_secure_shell_ssh</link>
		<comments>http://spalinux.com/2008/10/introduction_to_secure_shell_ssh#comments</comments>
		<pubDate>Fri, 03 Oct 2008 18:38:38 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Linux Shell]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[secure shell]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=230</guid>
		<description><![CDATA[SSH  (Secure Sell) คือโปรแกรมสำหรับล็อกอินและรันคำสั่งที่เครื่องปลายทางได้ โดยไม่จำเป็นต้องไปใช้งานที่หน้าจอคอนโซลของเครื่อง จุดประสงค์หลักของโปรแกรมคือทำหน้าที่แทนโปรแกรมประเภท rlogin, rsh หรือ telnet โดยจะมีการเข้ารหัสข้อมูล (encrypted) เพื่อความปลอดภัยของข้อมูลที่ส่งระหว่าง SSH Client และ SSH Server ชุดโปรแกรมที่ติดตั้งมากับลีนุกซ์ส่วนใหญ่คือ OpenSSH ประกอบด้วยเซิร์ฟเวอร์และไคลเอนต์ เครื่องปลายทางรันเซอร์วิส SSH Server เพื่อรองรับการล็อกอิน จากโปรแกรมประเภท SSH Client โดยคอนฟิกไฟล์หลักของเซิร์ฟเวอร์จะอยู่ในไดเร็กทอรี /etc/ssh/ ไฟล์คอนฟิกหลักคือไฟล์ /etc/ssh/sshd_config คำแนะนำ โปรแกรม PuTTY เป็นโปรแกรมประเภท SSH Client ที่สามารถรันได้บน Microsoft Windows ด้วยคุณสมบัติมากมาย รองรับทั้ง Secure Shell, Telnet และสามารถทำหน้าที่เป็น Terminal ผ่านทาง Serial หรือ COM Port ได้ด้วย (เช่นเดียวกับ [...]]]></description>
			<content:encoded><![CDATA[<p>SSH  (Secure Sell) คือโปรแกรมสำหรับล็อกอินและรันคำสั่งที่เครื่องปลายทางได้ โดยไม่จำเป็นต้องไปใช้งานที่หน้าจอคอนโซลของเครื่อง จุดประสงค์หลักของโปรแกรมคือทำหน้าที่แทนโปรแกรมประเภท rlogin, rsh หรือ telnet โดยจะมีการเข้ารหัสข้อมูล (encrypted) เพื่อความปลอดภัยของข้อมูลที่ส่งระหว่าง SSH Client และ SSH Server</p>
<p><span id="more-230"></span></p>
<p>ชุดโปรแกรมที่ติดตั้งมากับลีนุกซ์ส่วนใหญ่คือ OpenSSH ประกอบด้วยเซิร์ฟเวอร์และไคลเอนต์</p>
<p>เครื่องปลายทางรันเซอร์วิส SSH Server เพื่อรองรับการล็อกอิน จากโปรแกรมประเภท SSH Client โดยคอนฟิกไฟล์หลักของเซิร์ฟเวอร์จะอยู่ในไดเร็กทอรี /etc/ssh/ ไฟล์คอนฟิกหลักคือไฟล์ /etc/ssh/sshd_config</p>
<p><strong>คำแนะนำ</strong> โปรแกรม <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank">PuTTY</a> เป็นโปรแกรมประเภท SSH Client ที่สามารถรันได้บน Microsoft Windows ด้วยคุณสมบัติมากมาย รองรับทั้ง Secure Shell, Telnet และสามารถทำหน้าที่เป็น Terminal ผ่านทาง Serial หรือ COM Port ได้ด้วย (เช่นเดียวกับ HyperTerminal) และที่สำคัญสามารถงานใช้ได้ฟรีอย่างถูกต้อง (free software)</p>
<p>ในบทความนี้จะแนะนำวิธีการใช้คำสั่ง Secure Shell บนลีนุกซ์เป็นหลัก โดยตัวอย่างทั้งหมดจะทดสอบบน Fedora 9</p>
<h4>เริ่มต้นใช้งาน SSH Client (begin_ssh_client)</h4>
<p>เริ่มต้นทดลองใช้คำสั่ง ssh เพื่อล็อกอินไปยังเครื่องรีโมต ด้วยการพิมพ์คำสั่ง ssh แล้วตามด้วย IP Address หรือ Hostname ของเครื่องรีโมตปลายทาง</p>
<p>ตัวอย่างการล็อกอินไปที่เครื่องรีโมตครั้งแรก</p>
<pre>[user1@client ~]$ <strong>ssh 192.168.0.1
</strong>The authenticity of host '192.168.0.1 (192.168.0.1)' can't be established.
RSA key fingerprint is 5a:f2:9f:1b:8a:.....
Are you sure you want to continue connecting (yes/no)?<strong> yes
</strong>Warning: Permanently added '192.168.0.1' (RSA) to the list of known hosts.
user1@192.168.0.1's password:
Last login: Thu Oct  2 10:46:39 2008 from 192.168.0.15
[user1@server ~]$</pre>
<p>ถ้าเพิ่งเริ่มล็อกอินไปยังเครื่องรีโมตครั้งแรก จะมีข้อความเกี่ยวกับ RSA key ขึ้นมาถามว่า yes หรือ no การตอบ yes คือการยอมรับคีย์ (RSA key) จากเซิร์ฟเวอร์ปลายทางมา เพื่อใช้ในการเข้ารหัสระหว่างไคลเอนต์และเซิร์ฟเวอร์ ต้องตอบ yes อย่างเดียวเท่านั้นเพื่อยอมรับคีย์นี้ ถ้าตอบ no ไปก็ไม่สามารถล็อกไปยังเครื่องปลายทางได้</p>
<p>เมื่อตอบ yes ไป คีย์ที่ได้รับมา เครื่องไคลเอนต์จะเก็บคีย์นี้ไว้ในรายชื่อที่เรียกว่า ‘known hosts’ โดยจะบันทีกเป็นไฟล์อยู่ในไดเร็กทอรี $HOME/.ssh/ ($HOME คือ home directory ของผู้ที่ใช้คำสั่งบนเครื่องไคลเอนต์)</p>
<p>ตัวอย่างไฟล์ที่เก็บ known hosts</p>
<pre>[user1@client1 ~]$ cat .ssh/known_hosts
192.168.0.1 ssh-rsa AAAAB..........................</pre>
<p>ประการหนึ่งที่เก็บรายชื่อ known hosts ไว้ ด้วยเหตุผลทางด้านความปลอดภัย (Security) โดยคีย์ที่เก็บไว้ในไฟล์นี้สามารถใช้ในการเปรียบเทียบกับคีย์ที่ได้รีบมาใหม่จากเซิร์ฟเวอร์ ว่าตรงกันหรือไม่ เพื่อยืนยันในครั้งต่อที่ล็อกอินเข้าไปเครื่องเดิมนี้ว่า เป็นเครื่องที่ถูกต้อง ใช่ที่เราต้องการจริงๆ ไม่ใช่เครื่องอื่นๆ ที่ปลอมแปลง IP Address มาตรงกัน</p>
<p>ตัวอย่างการล็อกอินไปที่เครื่องที่ถูกปลอมแปลง IP Address โดยจะมีข้อความฟ้องว่าคีย์ที่ได้มาไม่ถูกต้อง</p>
<pre>[user1@client ~]$ <strong>ssh 192.168.0.1</strong>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
<span style="color: #ff0000;">Someone could be eavesdropping on you right now (man-in-the-middle attack)!
</span>It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
5a:f2:9f:...
Please contact your system administrator.
Add correct host key in /home/user1/.ssh/known_hosts to get rid of this message.
Offending key in /home/user1/.ssh/known_hosts:1
RSA host key for 192.168.0.1 has changed and you have requested strict checking.
Host key verification failed.</pre>
<p>วิธีการแก้ไขถ้าเจอข้อความแบบนี้ คือต้องตรวจสอบดูก่อนว่าเครื่องปลายทางที่เราจะล็อกเข้าไปนั้นเป็นเครื่องที่ถูกต้องจริงๆ โดยเปรียบเทียบคีย์ของ Secure Shell ซึ่งถูกเก็บไว้ในไฟล์ /etc/ssh/ssh_host_rsa_key.pub ซึ่งอาจมีการเปลี่ยนแปลงได้ ด้วยการติดตั้งลีนุกซ์ใหม่ หรือใช้คำสั่ง ssh-keygen ในการสร้างคีย์ใหม่</p>
<p>ถ้าดูแล้วเป็นเครื่องที่ถูกต้องจริงๆ วิธีการแก้ไขคือแก้ไฟล์ $HOME/.ssh/known_hosts โดยลบบรรทัดที่มี IP Address ของเครื่องปลายทางออกไป แล้วพิมพ์คำสั่ง ssh อีกครั้ง จะมีข้อความถาม yes หรือ no เหมือนครั้งแรก เพื่อเก็บคีย์ใหม่เข้าไปในไฟล์ known_hosts อีกครั้ง</p>
<p>คำเตือน แต่ถ้าตรวจสอบเครื่องปลายทางแล้วไม่ถูกต้อง อาจเป็นเครื่องของคนที่พยายามเจาะระบบด้วยการปลอมแปลง IP Address ก็เป็นได้เพื่อคอยดักเก็บรหัสของเรา เพราะฉะนั้นห้ามทำตามวิธีด้านบนเด็ดขาด ให้ปรึกษาคนดูแลระบบเพื่อแก้ไขโดยด่วน</p>
<h4>ระบุชื่อ user ที่ต้องการล็อกอิน (Specify user login)</h4>
<p>โดยดีฟอลต์เมื่อใช้คำสั่ง ssh บนไคลเอนต์ เพื่อล็อกไปยังเซิร์ฟเวอร์ โปรแกรม ssh จะพยายามล็อกอินด้วย username ของคนที่รันคำสั่ง เช่นผู้ใช้ที่ชื่อว่า user1 พิมพ์คำสั่ง ssh 192.168.0.1 จะเป็นการล็อกอินไปที่เครื่อง 192.168.0.1 ด้วยชื่อผู้ใช้ user1</p>
<p>ถ้าต้องการระบุเป็นชื่ออื่น สามารถใช้ออปชั่น ‘-l’ แล้วตามด้วยชื่อผู้ใช้ปลายทาง หรือพิมพ์ ในรูปแบบ <a href="mailto:user@hostname">user@hostname</a>  เช่น ต้องการล็อกอินไปยังปลายทางด้วยชื่อผู้ใช้ user2 สามารถทำได้สองวิธีแล้วแต่ถนัดดังนี้</p>
<p>วิธีแรก ใช้ออปชั่น ‘-l’ แล้วตามด้วยชื่อผู้ใช้ปลายทาง</p>
<pre>[user1@client ~]$ <strong>ssh -l user2 192.168.0.1
</strong>user1@192.168.0.1's password:</pre>
<pre>Last login: Thu Oct  2 11:22:24 2008 from 192.168.0.15
[user2@server ~]$</pre>
<p>วิธีที่สอง ใช้รูปแบบ user@hostname</p>
<pre>[user1@client ~]$ <strong>ssh user2@192.168.0.1
</strong>user1@192.168.0.1's password:</pre>
<pre>Last login: Thu Oct  2 11:23:13 2008 from 192.168.0.15
[user2@server ~]$</pre>
<h4>การรันคำสั่งบนเครื่องปลายทางด้วย SSH (Run remote command with SSH)</h4>
<p>ในบางครั้งเราต้องการเพียงแค่รันคำสั่งบนเครื่องปลายทาง เช่นต้องการตรวจสอบสถานะการทำงานของเครื่องปลายทางด้วยคำสั่ง uptime และ free แทนที่ต้องล็อกอินเข้าไปที่เครื่องปลายทางเลย สามารถใช้คำสั่ง ssh แล้วระบุคำสั่งที่ต้องการรันบนเครื่องรีโมตได้เลย โดยให้อยู่ในเครื่องหมาย single-quote ‘</p>
<p>ตัวอย่างการรันคำสั่งบนเครื่องปลายทางด้วย ssh</p>
<pre>[user1@client ~]$ <strong>ssh user2@192.168.0.1 'uptime; echo; free'
</strong>user1@192.168.0.1's password:
 16:01:39 up 2 days, 13:17,  4 users,  load average: 0.03, 0.02, 0.00</pre>
<pre>             total       used       free     shared    buffers     cached
Mem:        515064     235620     279444          0      48516     102124
-/+ buffers/cache:      84980     430084
Swap:       987956         52     987904</pre>
<p>ผลลัพธ์ที่ได้จะเหมือนกับการล็อกอินเข้าไปที่เครื่องปลายทางก่อน แล้วค่อยรันคำสั่งต่างๆ</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.openssh.com" target="_blank">OpenSSH</a></li>
<li><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank">PuTTY: A Free Telnet/SSH Client</a></li>
</ul>
<p><a href="http://www.openssh" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/10/introduction_to_secure_shell_ssh/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
