git设置ssh key 同时配置Gitee和GitHub

 

清除git的全局设置

以下所有命令建议在 git bash 中完成

如果是之前没设置过的,就不用清除了。

可以通过git config --global --list来查看是否设置过。

git config --global --unset user.name "你的名字"
git config --global --unset user.email "你的邮箱"

生成新的 SSH keys

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "111@qq.com"

ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "222@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

或者绝对路径
ssh-add /c/Users/qingy/.ssh/id_rsa_workttt.github
ssh-add /c/Users/qingy/.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
Are you sure you want to continue connecting (yes/no/[fingerprint])? 

第一次会连接让你输入yes/no ,输入yes,就能看到Hi了。

 

posted @ 2023-04-07 22:52  Dz&Ying  阅读(87)  评论(0编辑  收藏  举报