git 配置多个用户账号邮箱
Git默认一台设备一个SSH-Key,但是实际情况中,我们会将个人和公司的Git账号分开,公司的邮箱注册公司内部的代码管理平台,平时工作用;个人的邮箱注册GitHub、Gitee等,自己开发用,那么如何用Git去生成、配置多个账户呢?
1. 生成SSH-Key
首先生成公司key
$ ssh-keygen -t rsa -C 'xxxxx@company.com' -f ~/.ssh/company_id_rsa
再生成个人key
$ ssh-keygen -t rsa -C 'xxxxx@126.com' -f ~/.ssh/github_id_rsa
2. 将SSH-Key添加到平台上
打开~/.ssh文件夹,可以看到刚刚生成的SSH-Key:
$ cd ~/.ssh
$ ls
├── company_id_rsa
├── company_id_rsa.pub
├── github_id_rsa
├── github_id_rsa.pub
3.本地配置文件
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
# company
Host company.com
HostName company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/company_rsa