หมายเหตุ: ssh-copy-id ต่อท้าย กุญแจไปยัง .ssh/authorized_key ของโฮสต์ระยะไกล
เมื่อไม่มีการส่งค่าสำหรับ option -i และหาก ~/.ssh/identity.pub ไม่สามารถใช้งานได้ ssh-copy-id จะแสดงข้อความแสดงข้อผิดพลาดต่อไปนี้
ต่อไปนี้เป็นสิ่งที่น่ารำคาญเล็กน้อยของ ssh-copy-id
คุณสามารถเข้าสู่ระบบเซิร์ฟเวอร์ Linux ระยะไกลได้โดยไม่ต้องป้อนรหัสผ่านใน 3 ขั้นตอนง่ายๆ โดยใช้ ssky-keygen และ ssh-copy-id ตามที่อธิบายไว้ในบทความนี้
06รหัส>
ssh-keygen สร้างคีย์สาธารณะและคีย์ส่วนตัว ssh-copy-id คัดลอกกุญแจสาธารณะของโฮสต์ภายในเครื่องไปยังไฟล์authority_keysของโฮสต์ระยะไกล ssh-copy-id ยังกำหนดสิทธิ์ที่เหมาะสมให้กับบ้านของโฮสต์ระยะไกล ~/.ssh และ ~/.ssh/authorized_keys
18รหัส>
บทความนี้ยังอธิบายถึงปัญหาเล็กน้อย 3 ประการในการใช้ ssh-copy-id และวิธีใช้ ssh-copy-id ร่วมกับ ssh-agent
ป> ขั้นตอนที่ 1:สร้างคีย์สาธารณะและคีย์ส่วนตัวโดยใช้ ssh-key-gen บนโฮสต์ท้องถิ่น
jsmith@local-host$ [Note: You are on local-host here]
jsmith@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host
ขั้นตอนที่ 2:คัดลอกคีย์สาธารณะไปยังโฮสต์ระยะไกลโดยใช้ ssh-copy-id
jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
ขั้นตอนที่ 3:เข้าสู่ระบบโฮสต์ระยะไกลโดยไม่ต้องป้อนรหัสผ่าน
jsmith@local-host$ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH did not ask for password.]
jsmith@remote-host$ [Note: You are on remote-host here]
24รหัส>
3 ขั้นตอนง่ายๆ ข้างต้นควรทำให้งานสำเร็จในกรณีส่วนใหญ่
34รหัส>
นอกจากนี้เรายังพูดคุยในรายละเอียดก่อนหน้านี้เกี่ยวกับการดำเนินการ SSH และ SCP จาก openSSH ถึง openSSH โดยไม่ต้องป้อนรหัสผ่าน
42รหัส>
หากคุณใช้ SSH2 เราได้พูดคุยกันก่อนหน้านี้เกี่ยวกับการดำเนินการ SSH และ SCP โดยไม่ต้องใช้รหัสผ่านจาก SSH2 ถึง SSH2 จาก OpenSSH ถึง SSH2 และจาก SSH2 ถึง OpenSSH
59รหัส> ป> การใช้ ssh-copy-id พร้อมกับ ssh-add/ssh-agent
jsmith@local-host$ ssh-copy-id -i remote-host
/usr/bin/ssh-copy-id: ERROR: No identities found
64รหัส>
หากคุณได้โหลดคีย์ไปยัง ssh-agent ใช้ ssh-add จากนั้น ssh-copy-id จะได้รับกุญแจจาก ssh-agent เพื่อคัดลอกไปยังโฮสต์ระยะไกล กล่าวคือ จะคัดลอกคีย์ที่ได้รับจาก ssh-add -L คำสั่งไปยังโฮสต์ระยะไกล เมื่อคุณไม่ผ่าน option -i ไปที่ ssh-copy-id .jsmith@local-host$ ssh-agent $SHELL
jsmith@local-host$ ssh-add -L
The agent has no identities.
jsmith@local-host$ ssh-add
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)
jsmith@local-host$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79DyBV
aHrtPhTYpq7kIEMUNzApnyxsHpH1tQ/Ow== /home/jsmith/.ssh/id_rsa
jsmith@local-host$ ssh-copy-id -i remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[Note: This has added the key displayed by ssh-add -L]
สิ่งที่น่ารำคาญเล็กน้อยสามประการของ ssh-copy-id
79รหัส> ป>
81รหัส>
หากคุณชอบบทความนี้ โปรดบุ๊กมาร์กไว้ที่ อร่อย และสะดุด . ป>