設定 github 帳號的 git ssh key

我們可以使用 git 的 https:// protocol 來透過 HTTP auth 來存取 github 的 git repos 外﹐也可以使用 git 的 ssh:// protocol 來存取 github。

先在 command line,使用 ssh command 來產生和加入自己的 ssh key (RSA v2)。

$ ssh -t rsa -C “[email protected]”
$ ssh-add

然後登入 github.com,在 Account Setting 的 SSH Keys 加入自己的 SSH Keys (Add SSH Keys),再把 ~/.ssh/id_rsa.pub 的內容貼在 Key 的一欄內﹐完成後進行一次測試。

$ ssh -T [email protected]
Hi sammyfung! You’ve successfully authenticated, but GitHub does not provide shell access.

這樣便成功了。

About Sammy Fung

Sammy Fung 是開放源碼倡導者,Python Software Foundation Fellow,創辦 Open Source Hong Kong、香港開源年會及 PyCon HK,曾任 GNOME Foundation 董事,現為開發者關係專家,致力推廣開源軟件、開放數據與開源 AI。