之前單獨為 gitee 添加 SSH 公鑰
關(guān)聯(lián)文件 | 碼云 gitee
【增】為 github 添加 SSH 公鑰
切到 ~/.ssh
目錄下,欲執(zhí)行以下官方演示命令,將在 .ssh 目錄下默認生成 id_rsa
文件。
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
可以預(yù)見會與 gitee 那一套有沖突贰锁。
- 因此,對之前 gitee 生成公鑰時的關(guān)聯(lián)文件進行重命名
mv id_rsa id_rsa_gitee
mv id_rsa.pub id_rsa_gitee.pub
- 為 github 生成 SSH 公鑰并指定命名
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f "id_rsa_github"
關(guān)聯(lián)文件 | GitHub
- 將賬戶添加密鑰,內(nèi)容為
id_rsa_github.pub
中的字符
拷貝到剪切板的命令如下:
# Mac
$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
# Windows
$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
# Linux
$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
- 進行連接測試岭参,結(jié)果發(fā)生了意外:Permission denied(出現(xiàn)原因:多個git環(huán)境下,使用了自定義的秘鑰名稱)
ssh -T git@github.com
failure :(
解決方案:新建 config 文件尝艘,進行配置演侯,如下
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
再次進行連接測試,就好了背亥!
success :)