清除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


Last modification:August 17, 2020
如果觉得我的文章对你有用,请随意赞赏