git 同时管理Github和Gitee
1.取消git全局配置
取消全局的user.name和user.email
git config --global --unset user.name "xxx"
git config --global --unset user.email "xxx"
其中xxx
是以前配置的信息,可以通过 下边命令查看
git config --global --list
2.生成new的ssh keys
如果需要github和gitee都能存在,那么就需要生成github和gitee的id_rsa, 然后放在一起
生成Github 和 Gitee的keys
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "xxx"
注:其中
xxx
是github平台的注册邮箱ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "..."
注:其中
...
是你gitee平台的注邮箱将生成的新keys添加到ssh agent
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github ssh-add ~/.ssh/id_rsa.gitee exit
配置config文件
在.ssh文件夹下面配置config文件
vim ~/.ssh/config
# github Host github.com Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.github Port 443 # gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.gitee
3.平台设置SSH
钥匙和配置文件搞定后,就需要将我们的公钥放入到我们的平台中了
Github:复制
~/.ssh/id_rsa.github.pub
的内容到Github公钥Settings > SSH and GPG keys > New SSH key
Gitee:复制
~/.ssh/id_rsa.gitee.pub
的内容到Gitee公钥设置 > 安全设置 > SSH公钥
4.测试是否成功
Github
ssh -T git@github.com
结果:
Hi 766564616! You've successfully authenticated, but GitHub does not provide shell access.
Gitee
ssh -T git@gitee.com
结果:
Hi 神秘的小岛岛! You've successfully authenticated, but GITEE.COM does not provide shell access.
问题:
Bad owner or permissions on /Users/tuyuankun/.ssh/config
sudo chmod 600 config ~/.ssh/config
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for ‘/Users/tuyuankun/.ssh/id_rsa.gitee’ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for ‘/Users/tuyuankun/.ssh/id_rsa.github’ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
sudo chmod 700 ~/.ssh/id_rsa.gitee ~/.ssh/id_rsa.github
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 tuyrk@qq.com
文章标题:git 同时管理Github和Gitee
文章字数:480
本文作者:神秘的小岛岛
发布时间:2019-10-29, 13:12:16
最后更新:2019-11-30, 11:19:04
原始链接:https://www.tuyrk.cn/git-manage-github-gitee/版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。