自己在使用 Git 代码托管平台时,往往需要放到多个不同的托管平台里,Gitee、Github、GitCode 等等,不同的网站账号不同,需要生成的密钥也就不同,这里就可以通过配置多平台账号的方式来解决这个问题。
1、生成密钥
输入以下命令生成密钥:
代码语言:javascript
复制
ssh-keygen -t rsa -C "example@gmail.com"

请添加图片描述
【1】 生成 Gitee 的密钥

请添加图片描述
【2】生成 Github 的密钥

请添加图片描述
【3】生成 Gitcode 的密钥

请添加图片描述
2、配置多账户
在.ssh文件夹下面新建一个命名为config的文件,编辑如下内容
代码语言:javascript
复制
#github Host github.com HostName github.com IdentityFile ~/.ssh/id_rsa_github User user1
#gitee
Host gitee.com
HostName gitee.com
IdentityFile ~/.ssh/id_rsa_gitee
User user2
#gitcode
Host gitcode.net
HostName gitcode.net
IdentityFile ~/.ssh/id_rsa_gitcode
User user3
3、把公钥输入在 SSH公钥

请添加图片描述
4、测试是否连接成功
代码语言:javascript
复制
ssh -T git@github.com
ssh -T git@gitee.com
ssh -T git@gitcode.net

请添加图片描述
测试成功即可!