1. 進入ssh目錄
cd ~/.ssh
2. 使用命令分別創建兩個平台的公鑰
ssh-keyen -t rsa -C "xxxxxx@xxx.com" -f "id_rsa_gitee"
ssh-keyen -t rsa -C "xxxxxx@xxx.com" -f "id_rsa_github"
完成后,目錄內容如下:
-rw------- 1 lambda lambda 1679 Jun 14 10:51 id_rsa_gitee
-rw-r--r-- 1 lambda lambda 400 Jun 14 10:51 id_rsa_gitee.pub
-rw------- 1 lambda lambda 1679 Apr 1 13:44 id_rsa_github
-rw-r--r-- 1 lambda lambda 399 Apr 1 13:44 id_rsa_github.pub
-rw-r--r-- 1 lambda lambda 2434 Jun 14 11:05 known_hosts
3. 將產生的公鑰xxx.pub內容分別配置到Github和Gitee。
4. 創建config文件,解決SSH沖突
在.ssh目錄下創建config文件,添加如下內容:
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
5. 測試
命令:
ssh -T git@gitee.com
# 或
ssh -T git@github.com
成功:
Hi xxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
6. 遇到問題
在測試環節,有時會出現如下錯誤:
# Linux
Bad owner or permissions on /home/lambda/.ssh/config
# Windows
Bad owner or permissions on C:\\Users\\Ran\\.ssh\\config
解決辦法
- Linux
sudo chmod 600 ~/.ssh/config
- Windows
1. 查看PATH環境中是否存在C:\Windows\System32\OpenSSH\ssh.exe <br>
2. 將C:\Windows\System32\OpenSSH\ssh.exe改成C:\Program Files\Git\usr\bin\ssh.exe <br>
參考
https://blog.csdn.net/weixin_36191602/article/details/80946242
https://stackoverflow.com/questions/49926386/openssh-windows-bad-owner-or-permissions