環境

macOS

實作

  • 生成 SSH Key

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • 取得生成的公鑰

    cat /Users/你的使用者名稱/.ssh/id_rsa.pub
    例如:cat /Users/kunjili/.ssh/id_rsa.pub

    會輸出類似以下的內容,稍後設置會用到

    ssh-rsa AAAAB3Nza(中間略)b9gOxL0tSVMBQ== kunji.li@outlook.com
  • 將公鑰設置到 Github
    到 Github 頁面找到你的頭像 001

    Settings 002

    SSH and GPG keys 003

    在 SSH keys 的地方選擇 New SSH keys 004

    然後標題可以隨便取
    內容輸入剛剛資料夾內的 id_rsa.pub 檔案全部內容 005

  • 測試

    新增成功後測試看看

    ssh -T git@github.com

    成功的話會看到類似以下訊息

    Hi occultationtw! You've successfully authenticated, but GitHub does not provide shell access.

參考資料