如何在 Eclipse 上使用多个 Git SSH 密钥? [英] How to use multiple Git SSH keys on Eclipse?
问题描述
我查看了几个答案和论坛以寻求解决方案,但找不到一个有效的方法.
I looked several answers and forums for a solution but I could not find a single one that works.
我有这个场景:
- Eclipse Luna 服务版本 2 (4.4.2)
- Ubuntu 14.04 x64
- 我的
~/.ssh
文件夹中的两个 ssh 密钥 - 两个 bitbucket 帐户(一个用于个人项目,一个用于企业)
- 只能使用我的主键 (~/.ssh/id_rsa) 访问的 git 存储库
- 只能使用我的辅助密钥 (~/.ssh/other) 访问的 git 存储库
- 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)
我创建了一个 ~/.ssh/config
文件,内容如下:
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
为了理智起见,我也使用 ssh-add
添加了第二个密钥.运行 ssh-add -l
列出两个键.
And for the sake of sanity I added the second key using ssh-add
as well. Running ssh-add -l
lists both keys.
使用命令行时,所有 git 命令都像魅力一样工作,两个存储库.但是在使用 Eclipse 时,我总是在尝试使用辅助密钥从存储库克隆或拉取时出现 Invalid remote: origin
错误:
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.
我在 Window > 添加了辅助键首选项 >网络连接 >SSH2 >私钥
,并将GIT_SSH
环境变量设置为指向我的ssh
可执行文件:
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
我已经多次重启 Eclipse 甚至操作系统,但都没有成功.
I've restarted Eclipse and even the OS several times, with no luck.
因为我可以毫无问题地从命令行使用 git,所以我倾向于认为 Eclipse 有问题.
Since I can use git from the command line without problems, I tend to believe there's something wrong with Eclipse.
如何在 Eclipse 上使用多个 Git SSH 密钥?或者如何强制 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
?您不会在一个 Host
部分声明多个条目名称.
Host bitbucket bitbucket.org
? You don't declare multiple entry names on one Host
section.
我希望在 ssh 配置文件中看到声明多个键:
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
你会像
bitbucketuserA:userA/myrepo1
bitbucketuserB:userB/myrepo2
(这类似于我为如何从已添加 SSH 密钥的办公室计算机处理个人 GitHub 存储库的建议)与工作相关的 GitHub 帐户?")
这篇关于如何在 Eclipse 上使用多个 Git SSH 密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!