This is G o o g l e's cache of http://www.debianclub.org/node/49 as retrieved on 21 Jan 2007 02:47:09 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?hl=en&q=cache%3Ahttp%3A%2F%2Fwww.debianclub.org%2Fnode%2F49&btnG=Search


Google is neither affiliated with the authors of this page nor responsible for its content.

User login

Links

debianclub.com
debian.org
ubuntuclub.com
blognone.com

Syndicate

Syndicate content

ssh แบบไม่ต้องถามรหัสผ่าน

เอามาจาก ThaiLinuxCafe : ทดลอง ssh อย่างง่าย

จะทำ ssh-key ใช้สำหรับเวลาล็อกอินเข้าเซิร์ฟเวอร์ผ่าน ssh เพื่อให้ไม่ต้องใส่รหัสผ่านทุกครั้ง

สมมุติฐานคือ เราต้องการล็อกอินเป็น root ของเครื่องเซิร์ฟเวอร์ server1 มีไอพีเป็น 192.168.1.1 เราชื่อ user1 อยู่ที่เครื่อง client1

1. ทำที่เครื่อง server1

1.1 ติดตั้ง ssh
server1:~# aptitude install ssh

2. ทำที่เครื่อง client1

2.1 ติดตั้ง ssh เหมือนกัน
user1@client1:~$ sudo aptitude install ssh

2.2 สร้างกุญแจให้กับ ssh 1 ดอก
user1@client1:~$ ssh-keygen -t dsa
( รอ 1 เพลิน )
หน้าจอภาพตัวอย่างของผม

Enter file in which to save the key (/home/user1/.ssh/id_dsa): <<<--- {Enter}
Enter passphrase (empty for no passphrase): <<<--- {Enter}
Enter same passphrase again: <<<--- {Enter}
Your identification has been saved in /home/user1/.ssh/id_dsa.
Your public key has been saved in /home/user1/.ssh/id_dsa.pub.
The key fingerprint is:
15:16:63:52:d4:03:62:66:0a:a9:8a:29:59:af:60:69 user1@server1

2.3 คัดลอกกุญแจที่สร้างขึ้น ไปยังเซิร์ฟเวอร์ ผ่านโปรแกรม scp โดยสมมุติว่าเราต้องการล็อกอินเป็น root ที่เครื่อง server1
user1@client1:~$ scp ~/.ssh/id_dsa.pub root@server1:/root/.ssh
หน้าจอตัวอย่าง

The authenticity of host 'server1 (192.168.1.1)' can't be established.
RSA key fingerprint is 0f:7a:e1:1b:c9:de:52:d4:b9:4d:c6:f4:11:72:11:b4.
Are you sure you want to continue connecting (yes/no)? <<<--- yes
Warning: Permanently added 'server1,192.168.1.1' (RSA) to the list of known hosts.
Password: <<<--- ใส่รหัสผ่านของ root ที่ server1
id_dsa.pub                                    100%  600     0.6KB/s   00:00

2.4 ต่อไปต้องกลับไปทำที่เครื่อง server1 ซึ่งอาจใช้การ ssh ไปยัง server1 หรือไปทำหน้าจอ server1 โดยตรงเลยก็ได้ ในที่นี้สมมุติว่าทำผ่าน ssh แบบที่ต้องใส่รหัสผ่านปกติ
user1@client1:~$ ssh server1 -l root

Password: <<<--- ใส่รหัสผ่านของ root ที่ server1

3. ย้ายไปที่เครื่อง server1

3.1 ไปที่ไดเรคทอรี่ที่เก็บค่าของ ssh
server1:~# cd .ssh

3.2 นำกุญแจที่เราคัดลอกมา แปะไว้ที่ไฟล์ authorized_keys
server1:~# touch authorized_keys
server1:~# chmod 600 authorized_keys
server1:~# cat id_dsa.pub >> authorized_keys

3.3 ออกจาก server1
server1:~# exit

4. ย้ายกลับมาที่เครื่อง client1

4.1 ทดลองใช้ ssh เข้าไปที่ server1 ในชื่อ root
user1@client1:~$ ssh server1 -l root
เรียบร้อย ต่อไปก็ไม่ต้องถามรหัสผ่านแล้ว

วิธี copy กุญแจไปยัง server

ถ้าจะเอา public key ไปไว้ที่ server ต่างๆสามารถใช้คำสั่งนี้ได้ด้วย

ssh-copy-id -i ไฟล์public_key user@server

ง่ายกว่านะครับ

ssh-copy-id

ง่ายกว่ามากจริง ๆ ครับ ;D

จากตัวอย่าง ตั้งแต่ขั้นตอน 2.3 จนถึง 3.3 คำสั่งจะหดเหลือเพียง
ทำที่เครื่อง client1
2.3(ใหม่) - คัดลอกกุญแจไปยังเซิร์ฟเวอร์
user1@client1:~$ ssh-copy-id -i ~/.ssh/id_dsa.pub root@server1

สบายกว่ากันเยอะเลย ขอบคุณมากครับ :)

สะดวกจัด

สะดวกมาก จนลืม password ไป เลย ล่ะ ครับ *-*

ระวัง!!!

สะดวกจัด....!! ระวังอย่าทำ private key หล่นนะครับ :P
ทีสำคัญควรเก็บเป็นความลับสุดยอด แล้วอย่าเผลอ copy private key เข้าไปแทน public key ละ...มัน work เหมือนกันแต่มันจะไม่เป็นความลับเอานะ....