Gitee(码云)、Github同时配置ssh key
- 进入ssh目录
cd ~/.ssh
- 使用命令分别创建两个平台的公钥
ssh-keygen -t rsa -C "test@qq.com" -f "id_rsa_gitee"
ssh-keygen -t rsa -C "test@163.com" -f "id_rsa_github"
完成后,目录内容如下:
-rw------- 1 rpp staff 2.5K 6 18 2020 id_rsa
-rw-r--r-- 1 rpp staff 570B 6 18 2020 id_rsa.pub
-rw------- 1 rpp staff 2.5K 6 24 2020 id_rsa_gitee
-rw-r--r-- 1 rpp staff 570B 6 24 2020 id_rsa_gitee.pub
-rw------- 1 rpp staff 2.5K 6 24 2020 id_rsa_github
-rw-r--r-- 1 rpp staff 568B 6 24 2020 id_rsa_github.pub
-rw-r--r-- 1 rpp staff 3.7K 6 6 11:12 known_hosts
- 将产生的公钥xxx.pub内容分别配置到Github和Gitee
- 在.ssh目录下创建config文件,解决SSH冲突,添加如下内容:
# 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
- 测试,命令如下:
ssh -T git@gitee.com
或者
ssh -T git@github.com
成功后提示
Hi xxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
- 遇到问题,在测试环节,有时会出现如下错误:
# 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
- 查看PATH环境中是否存在C:\Windows\System32\OpenSSH\ssh.exe
- 将C:\Windows\System32\OpenSSH\ssh.exe改成C:\Program Files\Git\usr\bin\ssh.exe