背景
有时候我们的项目托管在多个平台上, 这就需要为每个托管平台设置相应的 SSH-key
当有多个git账号时,比如:
- 一个
gitee
用于公司内部的工作开发 - 一个
github
用于自己的项目开发
解决方法
1.生成一个 gitee
的 SSH-Key
$ ssh-keygen -t rsa -C 'x@x.com' -f ~/.ssh/gitee_id_rsa
此命令会生成 gitee_id_rsa
和 gitee_id_rsa.pub
两个文件
把 gitee_id_rsa.pub
添加到 gitee
个人中心里的 SSH 公钥里即可 教程传送门
2.生成一个 github
的 SSH-Key
$ ssh-keygen -t rsa -C 'x@x.com' -f ~/.ssh/github_id_rsa
此命令会生成 github_id_rsa
和 github_id_rsa.pub
两个文件
把 github_id_rsa.pub
添加到 github
个人中心里的 SSH keys 里即可
3.在 ~/.ssh 目录下新建一个config文件
添加如下内容, 其中 Host
和 HostName
填写 git
服务器的域名 IdentityFile
指定私钥的路径
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
用ssh命令分别测试
$ ssh -T git@github.com
Hi HoeXHe! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@gitee.com
Hi Hoe! You've successfully authenticated, but GITEE.COM does not provide shell access.
这样就完成了~
有用有用!
正好需要😁
喜迎2019,元旦快乐
2019万事如意☺
原来还能这样的
是啊,这样可以管理多个git平台的项目😁
有时间跟你学学
相互学习, 一起进步哈
666
get到了,很实用。