1.取消全局的账户配置
查看全局账户
git config --global user.name
如果存在,取消全局设置
git config --global --unset user.name
git config --global --unset user.email
新建ssh key
cd ~/.ssh
ssh-keygen -t rsa -C “new_user@email.com” # 生成新的ssh key
设置新的ssh key的名称
3.新密钥添加到ssh agent中
默认只添加了id_rsa,因此需要将新的ssh key 添加
ssh-add ~/.ssh/first_sa
如果添加报错:Could not open a connection to your authentication agent,尝试以下命令:
ssh-agent bash
ssh-add ~/.ssh/first_sa
4.修改config文件
在~/.ssh目录下找到config文件,如果没有就创建(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)
修改config 文件
host github
Hostname github.com
User wangzhiqiang1011
IdentityFile ~/.ssh/github_sa
host gitlab
Hostname git.corp.*****.com
User wangzhiqiang05
IdentityFile ~/.ssh/gitlab_sa
https://www.jianshu.com/p/7794dd2036f5