Catalog
  1. 1. 进入ssh目录
  2. 2. 使用命令分别创建两个平台的公钥
  3. 3. 完成后,目录内容如下:
  4. 4. 将产生的公钥xxx.pub内容分别配置到Github和Gitee。
  5. 5. 测试
  6. 6. 遇到问题
Github、Gitee同时配置SSH

进入ssh目录

1
cd ~/.ssh

使用命令分别创建两个平台的公钥

1
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"

完成后,目录内容如下:

1
2
3
4
5
-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

将产生的公钥xxx.pub内容分别配置到Github和Gitee。

  1. 创建config文件,解决SSH冲突
  2. 在.ssh目录下创建config文件,添加如下内容:
1
2
3
4
5
6
7
8
9
10
11
# 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

测试

1
2
3
4
5
6
#命令:
ssh -T git@gitee.com
# 或
ssh -T git@github.com
成功:
Hi xxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.

遇到问题

在测试环节,有时会出现如下错误:

  1. Linux
1
Bad owner or permissions on /home/lambda/.ssh/config
  1. Windows
1
Bad owner or permissions on C:\\Users\\Ran\\.ssh\\config
  1. 解决办法
1
2
3
4
5
6
7
8
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
Author: SiYuanJun
Link: http://blog.lvtcn.com/2019/11/02/Github%E3%80%81Gitee%E5%90%8C%E6%97%B6%E9%85%8D%E7%BD%AESSH/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Donate
  • 微信
  • 支付寶

Comment