1、如果有全局配置,移除全局配置
#查看配置
git config --list
#移除全局用户名、邮箱、密码
git config --global --unset user.name
git config --global --unset user.email
git config --global --unset user.password
2、配置公私钥
ssh-keygen -t rsa -C name@163.com
#第二次配置及以后,地址要变化,不然会覆盖前面的
#将id_rsa.pub中的内容复制到github上的SSH keys里
#让SSH识别新的私钥,将其添加到SSH agent中
ssh-add ~/.ssh/id_rsa_github
#如果出错,先执行下面语句,之后再执行一次ssh-add
ssh-agent bash
3、配置config
#若~/.ssh/config没有文件,则手动创建
touch config
#Default 第一个账号(123@123.com)
Host default
HostName 192.168.1.1
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
#github 第二个账号(name@163.com)
Host github
HostName github.com
PreferredAuthentications publickey
User name@163
IdentityFile ~/.ssh/id_rsa_github
4、测试
ssh -T git@github.com