多个git账号配置
在进行下列步骤前需要先查看git全局配置
git config --list
并清除共有的name, email, password的配置
git config --global --unset user.name
git config --global --unset user.email
git config --global --unset user.password
1. 用ssh-keygen命令生成一组新的id_rsa_new和id_rsa_new.pub。
ssh-keygen -t rsa -C "new email"
平时我们都是直接回车,默认生成id_rsa和id_rsa.pub。这里特别需要注意,出现提示输入文件名的时候要输入与默认配置不一样的文件名,比如: id_rsa_gitee。
2. 配置~/.ssh/config文件,以我自己的机器为例
#Default Git
Host defaultgit
HostName IP Address #域名也可
User think
PreferredAuthentications publickey
StrictHostKeyChecking no
IdentityFile ~/.ssh/id_rsa
#Second Git
Host gitee
HostName gitee.com
PreferredAuthentications publickey
StrictHostKeyChecking no
User think