【问题标题】:How to use multiple Git SSH keys on Eclipse?如何在 Eclipse 上使用多个 Git SSH 密钥?
【发布时间】:2015-09-19 12:03:21
【问题描述】:

我查看了几个答案和论坛以寻求解决方案,但找不到一个可行的。

我有这种情况:

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

我创建了一个~/.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: git@bitbucket.org: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 在单个项目中使用我的辅助键?

【问题讨论】:

    标签: eclipse git ssh


    【解决方案1】:

    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?”的建议)

    【讨论】:

    猜你喜欢
    • 2015-05-15
    • 2020-04-09
    • 2017-07-02
    • 1970-01-01
    • 2012-06-21
    • 2021-06-06
    • 1970-01-01
    • 2022-01-06
    • 2015-09-11
    相关资源
    最近更新 更多