Mac上配置多git帐号

//切换到ssh目录
cd ~/.ssh

//新建ssh-key
ssh-keygen -t rsa -C "email1"
//为新建的ssh-key重新命名
Enter file in which to save the key (/Users/bombvote-zql/.ssh/id\_rsa):user1\_rsa

//新建ssh-key
ssh-keygen -t rsa -C "email2"
//为新建的ssh-key重新命名
Enter file in which to save the key (/Users/bombvote-zql/.ssh/id\_rsa):user2\_rsa

因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:

ssh-add ~/.ssh/user1\_rsa  
ssh-add ~/.ssh/user2\_rsa  

修改~/.ssh/config文件(不存在则创建):

user1

Host user1.github.com  
HostName github.com  
User user1  
IdentityFile ~/.ssh/user1\_rsa  

user2

Host user2.github.com  
HostName github.com  
User user2  
IdentityFile ~/.ssh/user2\_rsa  

将pub公钥都添加到相应的github帐号上

测试是否可以:
ssh -T git@user1.github.com
Hi user1! You've successfully authenticated, but GitHub does not provide shell access.

ssh -T git@user2.github.com
Hi user2! You've successfully authenticated, but GitHub does not provide shell access.

Macgit

我来吐槽

*

*