Open Source How-To

You are here: Home > 3. Ubuntu 16.04 Server > การใช้งาน ssh-keygen บน ubuntu 16.04

การใช้งาน ssh-keygen บน ubuntu 16.04

 
 

บันทึกนี้ปรับปรุงล่าสุดเมื่อวันที่ 13-06-2560
ดูแลโดย WIBOON

สมมติว่าเครื่องที่ทำงานคือ 10.0.2.15
เข้าเป็น root

mama@ubuntu:~$ sudo su -
root@ubuntu:~# 

สร้าง ssh key กด Enter เพื่อใช้ค่า default

root@ubuntu:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.


นำ ssh key ไปใส่ไว้ที่ home ของ user ชื่อ mama ที่เครื่องที่ต้องการ เช่น 10.0.2.4 เป็นต้น

root@ubuntu:~# ssh-copy-id -i ~/.ssh/id_rsa.pub mama@10.0.2.4
mama@10.0.2.4's password: 


ถ้าทำถูกต้อง เราจะเข้าไปยังเครื่อง 10.0.2.4 ได้ โดยไม่ต้องใส่รหัสผ่าน

root@ubuntu:~# ssh mama@10.0.2.4
mama@ubuntu:~$ 


การใช้งาน เราจะนำเรื่องนี้มาใช้งานเกี่ยวกับการ backup files ได้
สร้างโฟลเดอร์ชื่อ backup เพื่อนำไฟล์จากเครื่องที่ต้องการมาเก็บไว้

mama@ubuntu:~$ mkdir -p backup/wordpress

แล้วออกด้วยคำสั่ง exit

mama@ubuntu:~$ exit
root@ubuntu:~# 
nach oben