เป็นขั้นตอนสุดท้ายในการย่อคำสั่ง SSH แล้วคือแทนที่จะมากรอก passphras เราก็ใช้ MacOs กรอก login passphras แทนเรา เมื่อเราเรียก ใช้คำสั่ง อย่าง ssh digitalocean_vps มันจะมีคำถามอยู่ว่า Enter passphrase for key ‘/Users/phunsanit/.ssh/digitalocean_vps‘: คือยังต้องกรอก passphras ให้อยู่นั่นละ แต่อยากจะใช้แค่ ssh digitalocean_vps ก็เข้าไปใน server ได้เลย ก็ทำได้โดยใช้ password manager ของ MacOS Keychain Access
ทำให้ mac ใช้ ssh-agent ให้เองอัตโนมัติ Set and Forget
- เปิดไฟล์ Config โดยคำสั่ง
nano ~/.ssh/config - เพิ่มไว้ บนสุด ของไฟล์
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa - บันทึก
- ปิด Terminal แล้วเปิดใหม่
โดยAddKeysToAgent yes: เมื่อคุณ SSH ครั้งแรกและใส่รหัสผ่าน มันจะจำกุญแจนั้นลง Agent ให้อัตโนมัติ UseKeychain yes: สำคัญมาก! มันสั่งให้ SSH ไปดึงรหัส Passphrase จาก Apple Keychain มากรอกให้เอง เช่น
BASH / Shell
# --- digitalocean_vps ---
Host digtalocean AddKeysToAgent yes HostName xx.xx.xxx.xxx IdentityFile ~/.ssh/digitalocean_vps Port 300 UseKeychain yes User B