同时使用多coding.net或者github.com账号

咱们常常须要同时使用多个git在线服务,好比本身的代码提交到github,公司的代码提交到coding.net。 若是只是使用一个,好比github,那很简单,生成一对ssh公私钥,把其中的公钥放到github上,而后每次操做就无需输入帐号密码了。那么两个甚至多个呢?其实也很简单:git

1.咱们须要作的就是为每个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

2.在~/.ssh文件夹下新建一个文件:config,文件内容以下:

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连接时,可以知道连哪一个,看下面的测试命令就明白了.测试

3.把各自公钥放到对应的服务网站上

4.测试一下

ssh -T git@github
ssh -T git@coding

5.到项目的.git文件夹下找到config文件,找到url配置,原来以下:

url = git@git.coding.net:user1/Project1.git

改为:网站

url = git@coding:user1/Project1.git

另:无论是2个仍是3个仍是更多,都是这个套路。若是是一个git服务,同时使用两个帐号也是相似,好比我有两个coding.net帐号,上面第2步就是:

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

相关文章
相关标签/搜索