一个mac设置一个或多个GitHub账号

  1. 新建SSH key:

$ cd ~/.ssh
ssh-keygen -t rsa -C "[email protected]"
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_work (#设置多个名字区别不同的账户)

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

ssh-add ~/.ssh/id_rsa_work
如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:
ssh-agent bash
ssh-add ~/.ssh/id_rsa_work

  1. 修改config文件

touch config
vim config

添加以下配置
#第一个账户
Host git.coding.net
User [email protected]
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work  // 生成的非默认地址的公钥存放点

#第二个账户
Host github.com
User [email protected]
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_aaa  // 生成的非默认地址的公钥存放点
  1. 把id_rsa_work.pub添加至ssh公钥

  2. 测试连接

ssh -T [email protected]

你可能感兴趣的:(一个mac设置一个或多个GitHub账号)