Git本地多用户配置

生成第一个ssh key

ssh-keygen -t rsa -C "yourmail@mail.com"

选择在哪里存放key的时候写个名字,比如 /c/Users/lake/.ssh/rainwi_rsa

id_rsa_self

加载私钥文件

ssh-add id_rsa_self

这里可能会出现could not open a connection to your authentication agent
需要先执行一条命令

ssh-agent bash

然后再次执行ssh-add就可以了
创建config文件

touch config

其中内容样式为:

# gitlab
Host git.iboxpay.com
HostName git.iboxpay.com //这里填你们公司的git网址即可
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
User zhangjun

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
User ZJsnowman

然后进行测试

ssh -vT git@github.com

不通的仓库需要设置不同的用户名和邮箱,如果之前有设置需要unset

git config --global --unset user.name
git config --global --unset user.email

然后在不同的仓库下设置

git config user.name "yourname"
git config user.email "youremail"
Last modification:June 6th, 2019 at 03:54 pm
If you think my article is useful to you, please feel free to appreciate