如何在Eclipse上使用多个Git SSH密钥? [英] How to use multiple Git SSH keys on Eclipse?
问题描述
我有这种情况:
- Eclipse Luna服务版本2(4.4.2)
- Ubuntu 14.04 x64
- 两个ssh密钥在我的
〜/ .ssh
文件夹中 - 两个bitbucket帐户(一个用于个人项目,一个用于企业)
- 只能使用我的主键(〜/ .ssh / id_rsa)访问的git存储库
- 只能使用我的辅助键(〜/ .ssh / other)
我创建了一个〜/ .ssh / config
内容:
主机bitbucket bitbucket.org
主机名bitbucket.org
IdentityFile〜/ .ssh / id_rsa
IdentityFile〜/ .ssh / other
User git
为了理智,我还使用 ssh-add
添加了第二个键。运行 ssh-add -l </ code>列出两个键。
使用命令行时,所有git命令都像魅力,与这两个存储库。但是当使用Eclipse时,当尝试使用辅助键克隆或从存储库中拉出时,我总是得到无效的remote:origin
错误:
原因:org.eclipse.jgit.errors.NoRemoteRepositoryException:git@bitbucket.org:myuser / myrepository.git:conq:存取库访问被拒绝。
我在 Window>首选项>网络连接> SSH2>私钥
,并设置 GIT_SSH
环境变量指向我的 ssh
可执行文件:
$ echo $ GIT_SSH
/ usr / bin / ssh
我重新启动了Eclipse甚至操作系统了好几次,没有运气。
因为我可以从命令行使用git没有问题,我倾向于认为Eclipse有问题。
如何在Eclipse上使用多个Git SSH密钥?或者如何强制Eclipse在单个项目中使用我的辅助键?
主机bitbucket bitbucket。有机
?您不要在一个主机
部分声明多个条目名称。
我希望在ssh config中看到文件声明多个键:
主机bitbucketuserA
主机名bitbucket.org
IdentityFile〜/ .ssh / id_rsa
用户git
主机bitbucketuserB
主机名bitbucket.org
IdentityFile〜/ .ssh / other
用户git
你可以像使用ssh url一样使用
bitbucketuserA:userA / myrepo1
bitbucketuserB:userB / myrepo2
(这与我建议如何处理办公室计算机的个人GitHub回购,其SSH密钥已添加到工作相关的GitHub帐户?)
I looked several answers and forums for a solution but I could not find a single one that works.
I have this scenario:
- Eclipse Luna Service Release 2 (4.4.2)
- Ubuntu 14.04 x64
- Two ssh keys on my
~/.ssh
folder - Two bitbucket accounts (one for personal projects and one for enterprise)
- A git repository only accessible with my primary key (~/.ssh/id_rsa)
- A git repository only accessible with my secondary key (~/.ssh/other)
I created a ~/.ssh/config
file with the contents:
Host bitbucket bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/other
User git
And for the sake of sanity I added the second key using ssh-add
as well. Running ssh-add -l
lists both keys.
When using the command line, all git commands work like a charm, with both repositories. But when using Eclipse, I always get the Invalid remote: origin
error when trying to clone or pull from the repository with the secondary key:
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: git@bitbucket.org:myuser/myrepository.git: conq: repository access denied.
I added the secondary key at Window > Preferences > Network Connections > SSH2 > Private keys
, and set the GIT_SSH
environment variable to point to my ssh
executable:
$echo $GIT_SSH
/usr/bin/ssh
I've restarted Eclipse and even the OS several times, with no luck.
Since I can use git from the command line without problems, I tend to believe there's something wrong with Eclipse.
How to use multiple Git SSH keys on Eclipse? Or how to force Eclipse to use my secondary key on a single project?
Host bitbucket bitbucket.org
? You don't declare multiple entry names on one Host
section.
I would expect to see in a ssh config file declaring multiple keys:
Host bitbucketuserA
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
User git
Host bitbucketuserB
Hostname bitbucket.org
IdentityFile ~/.ssh/other
User git
And you would use ssh url like
bitbucketuserA:userA/myrepo1
bitbucketuserB:userB/myrepo2
(this is similar to what I suggested for "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?")
这篇关于如何在Eclipse上使用多个Git SSH密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!