自己在使用 Git 代码托管平台时,往往需要放到多个不同的托管平台里,Gitee、Github、GitCode 等等,不同的网站账号不同,需要生成的密钥也就不同,这里就可以通过配置多平台账号的方式来解决这个问题。
输入以下命令生成密钥:
ssh-keygen -t rsa -C "example@gmail.com"
【1】 生成 Gitee 的密钥
【2】生成 Github 的密钥
【3】生成 Gitcode 的密钥
在.ssh文件夹下面新建一个命名为config的文件,编辑如下内容
#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
ssh -T git@github.com
ssh -T git@gitee.com
ssh -T git@gitcode.net
测试成功即可!