git 多用户连接 gitee 和 github
一、通过邮箱生成公私钥(使用 git bash)
1 2 3 4 5 6
|
ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitee -C "youxiang@qq.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "youxiang@qq.com"
|


二、公钥设置进网站账户


三、在 git bash 上激活公钥,并授权
1 2 3 4 5 6 7 8 9 10
|
ssh -T git@gitee.com -i ~/.ssh/id_rsa_gitee
授权 控制台输入yes
ssh -T git@github.com -i ~/.ssh/id_rsa_github
授权 控制台输入yes
|

若出现失败
- 首先查看 .ssh 目录下是否有 known_hosts 文件,若有,先删除
- 查看ssh链接的 github 地址
如果出现 127.0.0.1 或 ::1,说明 github 的 ip 地址访问不对,使用以下命令获取github的ip地址存入hosts文件
1 2 3 4 5
| ## 下面命令都是在 cmd 中执行 # 获取 github ip地址存入 hosts 文件 nslookup github.com 8.8.8.8 # 刷新 dns 缓存(windows) ipconfig /flushdns
|
出现原因是用了 steam++ 修改了hosts
四、将私钥文件添加到 git
1 2 3 4 5 6
|
ssh-agent bash
ssh-add ~/.ssh/id_rsa_gitee ssh-add ~/.ssh/id_rsa_github
|
五、配置 config 文件
文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
| # config Host gitee.com HostName gitee.com IdentityFile C:\\Users\\25361\\.ssh\\id_rsa_gitee PreferredAuthentications publickey User git
Host github.com HostName github.com IdentityFile C:\\Users\\25361\\.ssh\\id_rsa_github PreferredAuthentications publickey User git
|
测试如下,即为成功
