ไฟล์ ~/.ssh/config เป็นไฟล์ที่เก็บ options ของ SSH Client โดยจะช่วยให้การ SSH ง่ายขึ้นแทนการใช้คำสั่งยาว ๆ เช่น แทนที่จะใช้
ssh [email protected] -p 2222 -i ~/.ssh/id_rsa_dev
ก็ใช้ได้แค่
ssh dev-server
ไฟล์ ~/.ssh/config ถูกสร้างขึ้นมา 2 วิธีหลัก ๆ คือ
- โดย Sourcetree (หรือโปรแกรม SSH Client อื่นๆ)
- โดยคำสั่ง
cd ~/.ssh
touch config
nano config
เนื้อหาในไฟล์จะเป็นประมาณ
# --- Specific Hosts ---
# --- github.com ---
Host github.com
AddKeysToAgent yes
HostName github.com
IdentityFile /Users/phunsanit/.ssh/phunsanit@GitHub
PreferredAuthentications publickey
UseKeychain yes
User git
# --- General / Defaults / Else ---
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
โปรแกรมจะเข้ามาอ่านโดยไล่ตาม Host ที่ตรงกัน แล้วถ้าไม่เจอจะเข้าไปใน Host *
โดย IdentityFile จะชี้ไปยัง SSH key ที่ใช้กับ host ที่สร้างไว้ โดย ssh-keygen หรือ key ที่ต้องการใช้
อ่านเพิ่มเติม