Home 程式語言軟體開發知識庫 Github 不能用 http clone 取得專案了, 要怎麼設定用 ssh

Github 不能用 http clone 取得專案了, 要怎麼設定用 ssh

by adcapdio

github 基於安全因素將 clone by http 給取消掉了!!! 那麼使用 ssh 去進行 clone 等的操作算是最原生的方法了!! 但是該怎麼進行呢? 其實不難, 只要透過以下幾個步驟就可以達成了!!

事前準備工作
1. 請先註冊好 github 帳號, 我們先架設我們的帳號叫做 Ahero2024TW
2. 隨意先建立一個 repository, 我們先假設這邊叫做 AAAAProject

Step 1 – create your own ssh key
如何建立 ssh key, 如果你是 linux 用戶我想這個問題應該很簡單!!
如果不知道怎麼進行, 我之後再補上, 或是可以參考這邊
https://phoenixnap.com/kb/git-clone-ssh
這邊我們假設你建立好的 key 組是以下兩個檔案
~/.ssh/id_github
~/.ssh/id_github.pub

這邊 ~/ 是在 unix 下帳號所屬的根目錄, 如果是在 windows 那你的目錄就是 C:/Users/你的帳號
所以 ~/.ssh 就是等於 windows 下的 C:/Users/你的帳號/.ssh

Step 2 – 將你的公鑰放上去 github
你登入到 github 後就可以選擇加入了, 詳情可以參考
https://phoenixnap.com/kb/git-clone-ssh

Step 3 – 進行測試
請在 windows 的 terminal (命令提示字元, 就是類似 dos 那個畫面視窗) 輸入以下指令
git -i .ssh/id_github -T git@github.com

你應該會看到他顯示以下打招呼的回應, 如果是 Permission denied 那就是失敗有問題喔!
Hi Ahero2024TW! bala ~~ bala~~~

Step 4 – 環境設定
請到 ~/.ssh 目錄下建立 config 檔案, 將以下內容放入

Host github.com
Hostname github.com
User Ahero2024TW
IdentityFile ~/.ssh/id_github 或是(擇一輸入 unix or windows) 
IdentityFile C:/Users/你的windows帳號/.ssh/id_github
IdentitiesOnly yes

存檔後即可

Step 5 – clone repository
接下來你可以到你想要放入專案的資料匣內進行以下指令
git clone git@github.com:Ahero2024TW/AAAAProject.git
看到 done 那麼就可發現檔案都已 clone 到 local 端了, 成功!!!

You may also like