How do I use multiple Git SSH keys on Eclipse?

I've searched several answers and forums for a solution, but I couldn't find any that work.

I have a scenario like this:

  • Eclipse Luna Service Release 2 (4.4.2)
  • Ubuntu 14.04 x64
  • Two ssh keys in my folder ~/.ssh

  • Two bitbucket accounts (one for personal projects and one for enterprise)
  • The git repository is only available with my primary key (~ / .ssh / id_rsa)
  • The git repository is only available with my additional key (~ / .ssh / other)

I created a file ~/.ssh/config

with content:

Host bitbucket bitbucket.org
    Hostname bitbucket.org
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/other
    User git

      

And for the sake of common sense, I added a second key using ssh-add

. At startup ssh-add -l

, both keys are listed.

When using the command line, all git commands work like a charm with both repositories. But when using Eclipse, I always get the error Invalid remote: origin

when trying to clone or pull from the repository using the secondary key:

Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: git@bitbucket.org:myuser/myrepository.git: conq: repository access denied.

      

I added an extra key in Window > Preferences > Network Connections > SSH2 > Private keys

and set an environment variable GIT_SSH

to point to my executable ssh

:

$echo $GIT_SSH
/usr/bin/ssh

      

I have restarted Eclipse and even the OS several times with no luck.

Since I can use git from the command line without any problem, I tend to believe that there is something wrong with Eclipse.

How do I use multiple git SSH keys on Eclipse? Or how do I get Eclipse to use my secondary key in the same project?

+3


source to share


1 answer


Host bitbucket bitbucket.org

? You are not declaring multiple record names in the same section Host

.

I would expect to see multiple keys declared in the ssh config file:

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 do I work with a personal GitHub repo from an office computer whose SSH key has already been added to the work-related GitHub account? ")

+3


source







All Articles