咱们常常须要同时使用多个git在线服务,好比本身的代码提交到github,公司的代码提交到coding.net。 若是只是使用一个,好比github,那很简单,生成一对ssh公私钥,把其中的公钥放到github上,而后每次操做就无需输入帐号密码了。那么两个甚至多个呢?其实也很简单:git
#ssh-keygen -t rsa -C "user1@email.com"
要注意的是这里生的文件要起个不同的名字:github
Enter file in which to save the key (/Users/user1/.ssh/id_rsa): /Users/wuminzhe/.ssh/id_rsa2
注:这里的email地址能够不留, -C 只是个备注选项ssh
Host coding Hostname git.coding.net PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Host github Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa2
这一步就是在git发起ssh连接时,可以知道连哪一个,看下面的测试命令就明白了.测试
ssh -T git@github ssh -T git@coding
url = git@git.coding.net:user1/Project1.git
改为:网站
url = git@coding:user1/Project1.git
Host coding1 Hostname git.coding.net PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Host coding2 Hostname git.coding.net PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa2
注:链接过程当中的用户校验是有密钥完成的,其余的什么email之类不是用来校验的,看看测试那步url