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

How to use multiple Git SSH keys on Eclipse?

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

我有这种情况:

我创建了一个 ~/.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 甚至 OS 好几次了,都没有成功。

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

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

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