zero_yu
zero_yu

Reputation: 503

Eclipse: An error occurred loading the SSH2 private keys

I am using eclipse Version: 2018-12 (4.10.0) on macOS Mojave Version 10.14.1. I followed the instruction on https://help.github.com/enterprise/2.9/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ to set up ssh keys for GitHub. I am able to "git clone" the repository in the terminal with no problem. However, when it came to eclipse, an exception occurred:

org.eclipse.jgit.api.errors.TransportException: git@github.***.com:EA/entity-matching.git: invalid private key: [B@47822527
    at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:222)
    at org.eclipse.jgit.api.LsRemoteCommand.call(LsRemoteCommand.java:161)
    at org.eclipse.egit.core.op.ListRemoteOperation.run(ListRemoteOperation.java:116)
    at org.eclipse.egit.ui.internal.clone.SourceBranchPage$8.run(SourceBranchPage.java:340)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Caused by: org.eclipse.jgit.errors.TransportException: git@github.***.com:EA/entity-matching.git: invalid privatekey: [B@47822527
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:191)
    at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:140)
    at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:280)
    at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:170)
    at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:200)
    ... 4 more
Caused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@47822527
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:664)
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:561)
    at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:407)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:367)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getJSch(JschConfigSessionFactory.java:399)
    at org.eclipse.egit.core.EclipseSshSessionFactory.createSession(EclipseSshSessionFactory.java:53)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:208)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:138)
    ... 8 more

I am sure the URI is correct. My ~/.ssh/congif is

Host *
 AddKeysToAgent yes
 UseKeychain yes
 IdentityFile ~/.ssh/id_rsa

Can anybody help me on this please?

Upvotes: 3

Views: 5285

Answers (3)

void pointer
void pointer

Reputation: 578

If someone not able to update it to Jsch (Like I am not able to do it in Spring Tool Suite) You may have to generate a new keypair using the -m PEM option like this:

ssh-keygen -t rsa -m PEM 

so it can be used by Jsch.

Reference - http://answers.neotys.com/questions/2218589-error-configure-git-connection-neoload-using-ssh-protocol-public-private-key

Upvotes: 0

VonC
VonC

Reputation: 1326686

This error would not occur with the EGit 5.3.0 (Feb. 2019)

In the last release we had introduced a new SSH client based on the Apache MINA sshd library as an alternative to the JSch-based client.
In EGit 5.3.0 the default settings are switched: by default, the Apache MINA implementation is used.

We plan to remove the old JSch SSH implementation completely in a future release of EGit.

Upvotes: 0

howlger
howlger

Reputation: 34255

Make sure, in Window > Preferences: General > Network Connections > SSH2 in the tab General that Private keys contains id_rsa.

Since Eclipse 2018-12 (which contains JGit/EGit 5.2) you can try in Window > Preferences: Team > Git to switch the SSH client from JSch to Apache MINA sshd (see this video showing it).

Upvotes: 5

Related Questions