清除git的全局设置
以下所有命令建议在 git bash 中完成
如果是之前没设置过的,就不用清除了。
可以通过git config --global --list
来查看是否设置过。
git config --global --unset user.name "你的名字"
git config --global --unset user.email "你的邮箱"
生成新的 SSH keys
GitHub 的钥匙
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "lx@qq.com"
疯狂回车即可。
Gitee 的钥匙
邮箱换一个。不要跟上面相同就行了。
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "lx@vip.qq.com"
疯狂回车即可。
完成后会在~/.ssh / 目录下生成以下文件。
- id_rsa.github
- id_rsa.github.pub
- id_rsa.gitee
- id_rsa.gitee.pub
识别 SSH keys 新的私钥
默认只读取 id_rsa,为了让 SSH 识别新的私钥,需要将新的私钥加入到 SSH agent 中
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee
多账号配置 config 文件
创建config文件
touch ~/.ssh/config
config 中填写的内容
#Default gitHub user Self
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
# gitee
Host gitee.com
Port 22
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
添加 ssh
https://github.com/settings/keys
将 id_rsa.github.pub 中的内容填进去,起名的话随意。
https://gitee.com/profile/sshkeys
将 id_rsa.gitee.pub 中的内容填进去,起名的话随意。
测试成功
ssh -T git@gitee.com
ssh -T git@github.com
第一次会连接让你输入yes/no ,输入yes,就能看到Hi了。
参考资料:https://www.jianshu.com/p/68578d52470c
版权属于:乐心湖's Blog
本文链接:https://xn2001.com/archives/557.html
声明:博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!
One comment
千万别同邮箱同密码同用户名注册这两个平台,稍微不注意就要进坑,我进了