如何在Eclipse上使用多个Git SSH密钥?

Gil*_*zan 3 eclipse git ssh

我看了几个答案和论坛的解决方案,但我找不到一个有效的.

我有这种情况:

  • Eclipse Luna Service Release 2(4.4.2)
  • Ubuntu 14.04 x64
  • 我的~/.ssh文件夹上有两个ssh键
  • 两个bitbucket帐户(一个用于个人项目,一个用于企业)
  • 只能使用我的主键访问的git存储库(〜/ .ssh/id_rsa)
  • 只能使用我的辅助密钥访问的git存储库(〜/ .ssh/other)

我创建了一个~/.ssh/config包含以下内容的文件:

Host bitbucket bitbucket.org
    Hostname bitbucket.org
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/other
    User git
Run Code Online (Sandbox Code Playgroud)

为了理智,我还添加了第二个密钥ssh-add.运行ssh-add -l列出两个键.

使用命令行时,所有git命令都像魅力一样,具有两个存储库.但是在使用Eclipse时,我总是Invalid remote: origin在尝试使用辅助密钥克隆或从存储库中提取时出错:

Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: git@bitbucket.org:myuser/myrepository.git: conq: repository access denied.
Run Code Online (Sandbox Code Playgroud)

我添加了二级密钥Window > Preferences > Network Connections > SSH2 > Private keys,并将GIT_SSH环境变量设置为指向我的ssh可执行文件:

$echo $GIT_SSH
/usr/bin/ssh
Run Code Online (Sandbox Code Playgroud)

我已经多次重启Eclipse甚至操作系统,没有运气.

由于我可以毫无问题地从命令行使用git,我倾向于认为Eclipse存在问题.

如何在Eclipse上使用多个Git SSH密钥?或者如何强制Eclipse在单个项目中使用我的二级密钥?

Von*_*onC 5

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
Run Code Online (Sandbox Code Playgroud)

你会使用ssh url

bitbucketuserA:userA/myrepo1
bitbucketuserB:userB/myrepo2
Run Code Online (Sandbox Code Playgroud)

(这类似于我建议的" 如何处理来自办公室计算机的个人GitHub仓库,其SSH密钥已经添加到与工作相关的GitHub帐户? ")