这篇文章主要介绍了有.ssh文件情况下同时使用github和gitee的操作流程。

1.在.ssh文件中打开git bash

1
2
3
# 生成github.com和gitee.com对应的私钥公钥
ssh-keygen -t rsa -C "19189@qq.com" -f "github_id_rsa"
ssh-keygen -t rsa -C "19189@qq.com" -f "gitee_id_rsa"

2.把github对应的公钥和oschina对应的公钥上传到对应服务器

1
2


3.在.ssh目录创建config文本文件并完成相关配置(最核心的地方)

1
2
3
4
5
6
7
8
9
10
11
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile C:\Users\jack\.ssh/gitee_id_rsa

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile C:\Users\jack\.ssh/github_id_rsa

4.执行测试命令测试是否配置成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 会自动在.ssh目录生成known_hosts文件把私钥配置进去
jack@jack-PC MINGW64 ~/.ssh
$ ssh -T git@github.com
The authenticity of host 'github.com (13.252.177.222)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.252.177.222' (RSA) to the list of known hosts.
Hi jiangleiundo! You've successfully authenticated, but GitHub does not provide shell access.

jack@jack-PC MINGW64 ~/.ssh
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (120.55.222.22)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,120.55.222.22' (ECDSA) to the list of known hosts.
Bad packet length 3643771916.
ssh_dispatch_run_fatal: Connection to 120.55.222.22 port 22: message authentication code incorrect

jack@jack-PC MINGW64 ~/.ssh
$ ssh -T git@gitee.com
Hi 小方块! You've successfully authenticated, but GITEE.COM does not provide shell access.

jack@jack-PC MINGW64 ~/.ssh
$