PlusMagi's Blog By Pitt Phunsanit

GIT: set SSH Client

ไฟล์ ~/.ssh/config เป็นไฟล์ที่เก็บ options ของ SSH Client โดยจะช่วยให้การ SSH ง่ายขึ้นแทนการใช้คำสั่งยาว ๆ เช่น แทนที่จะใช้
ssh user@192.168.1.10 -p 2222 -i ~/.ssh/id_rsa_dev
ก็ใช้ได้แค่
ssh dev-server

ไฟล์ ~/.ssh/config ถูกสร้างขึ้นมา 2 วิธีหลัก ๆ คือ

  1. โดย Sourcetree
  2. โดยคำสั่ง
    1. cd ~/.ssh
    2. touch config
    3. 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 ที่ต้องการใช้

อ่านเพิ่มเติม



Exit mobile version