2015-07-02 40 views
3

我看了几个答案和论坛的解决方案,但我找不到一个工程。如何在Eclipse上使用多个Git SSH密钥?

我有这样的场景:

  • Eclipse的月神服务版本2(4.4.2)
  • 的Ubuntu 14.04 64我~/.ssh文件夹
  • 两个SSH密钥
  • 两到位桶账户(一个用于个人项目和一个企业)
  • 一个只能用我的主键(〜/ .ssh/id_rsa)访问的git仓库
  • 一个Git仓库只与我的辅助键访问(的〜/ .ssh /其他)

我创建了一个~/.ssh/config文件与内容:

Host bitbucket bitbucket.org 
    Hostname bitbucket.org 
    IdentityFile ~/.ssh/id_rsa 
    IdentityFile ~/.ssh/other 
    User git 

而对于理智的缘故,我添加了第二使用ssh-add的密钥也是如此。运行ssh-add -l列出了这两个键。

当使用命令行时,所有git命令都像魅力一样工作,同时具有两个存储库。但是,使用Eclipse的时候,我总是试图克隆或与二级钥匙从仓库拉当Invalid remote: origin错误:

Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: [email protected]:myuser/myrepository.git: conq: repository access denied. 

我添加了辅助键在Window > Preferences > Network Connections > SSH2 > Private keys,并设置GIT_SSH环境变量指向我的ssh可执行文件:

$echo $GIT_SSH 
/usr/bin/ssh 

我已经重新启动Eclipse甚至操作系统几次,没有运气。

因为我可以从命令行使用git而没有问题,所以我倾向于认为Eclipse有问题。

如何在Eclipse上使用多个Git SSH密钥?或者如何强制Eclipse在单个项目上使用我的辅助键?

回答

3

Host bitbucket bitbucket.org?您不要在一个Host部分声明多个条目名称。

我希望看到的SSH配置文件中声明多个密钥:

Host bitbucketuserA 
    Hostname bitbucket.org 
    IdentityFile ~/.ssh/id_rsa 
    User git 

Host bitbucketuserB 
    Hostname bitbucket.org 
    IdentityFile ~/.ssh/other 
    User git 

你就可以使用SSH URL像

bitbucketuserA:userA/myrepo1 
bitbucketuserB:userB/myrepo2 

(这是类似于我建议“How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account? “)

+0

该文件是基于从[这个问题]接受的答案(http://stackoverflow.com/questions/2419566/best-way-to-use-multiple-ssh-private-keys-on-one -客户)。更改每个项目的ssh url工作 - 谢谢! –