Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Error loading the SSH2 private keys
Error loading the SSH2 private keys [message #1796428] Fri, 12 October 2018 18:28 Go to next message
Stefano Scaccabarozzi is currently offline Stefano ScaccabarozziFriend
Messages: 3
Registered: October 2018
Junior Member
Dear community,

every time I try to perform a git operation I get the error message Auth fail. Searching inside the error logs I found out the error message is generated by the following exception:

com.jcraft.jsch.JSchException: invalid privatekey: [B@3dbd0e97
	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.jsch.internal.core.Utils.loadPrivateKeys(Utils.java:105)
	at org.eclipse.jsch.internal.core.JSchCorePlugin.loadPrivateKeys(JSchCorePlugin.java:226)
	at org.eclipse.jsch.internal.core.JSchProvider.createSession(JSchProvider.java:45)
	at org.eclipse.egit.core.EclipseSshSessionFactory.createSession(EclipseSshSessionFactory.java:56)
	at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:200)
	at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:130)
	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.transport.FetchProcess.executeImp(FetchProcess.java:137)
	at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:123)
	at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1271)
	at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:243)
	at org.eclipse.egit.core.op.FetchOperation.run(FetchOperation.java:134)
	at org.eclipse.egit.ui.internal.fetch.FetchOperationUI.execute(FetchOperationUI.java:110)
	at org.eclipse.egit.ui.internal.fetch.FetchOperationUI$1.performJob(FetchOperationUI.java:136)
	at org.eclipse.egit.ui.internal.jobs.RepositoryJob.run(RepositoryJob.java:59)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)


It seems there is some kind of issue reading the private SSH key, but I'm pointing to the same one I use from command line and everything is working well there.

Am I doing something wrong? Any idea of how I could get this fixed?

I'm working with Eclipse Photon (4.8.0) on linux Mint 19 Cinnamon.

Thanks in advance for your attention,
Stefano
Re: Error loading the SSH2 private keys [message #1796730 is a reply to message #1796428] Thu, 18 October 2018 08:12 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 175
Registered: August 2016
Senior Member
What kind of keys did you specify? RSA, DSA, ECDSA, Ed25519, ... ? Note that the Java ssh library used by JGit cannot handle Putty keys, and cannot handle ed25519, and may have trouble with ECDSA-384/521. See also bug 520927. For now, a possible work-around is to set the GIT_SSH environment variable to make JGit use an external ssh tool, or use RSA keys.

[Updated on: Thu, 18 October 2018 08:13]

Report message to a moderator

Re: Error loading the SSH2 private keys [message #1796878 is a reply to message #1796730] Sat, 20 October 2018 15:01 Go to previous messageGo to next message
Stefano Scaccabarozzi is currently offline Stefano ScaccabarozziFriend
Messages: 3
Registered: October 2018
Junior Member
Hello Thomas,

thanks for your answer. I'm using RSA keys generated with open-ssh in order to gain access to a Bitbucket repository.
The strange point is that I am doing the same thing on my MacBook, and I don't get any kind of problem from there.

Stefano
Re: Error loading the SSH2 private keys [message #1796925 is a reply to message #1796878] Mon, 22 October 2018 12:49 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 175
Registered: August 2016
Senior Member
Looks like the ssh library used by EGit/JGit tries to load the default keys (the ones specified at Preferences->General->Network Connections->SSH2, field "Private keys", or perhaps a default id_rsa key in your ~/.ssh directory) and encounters a key stored in a format it cannot read.

From code inspection, it looks as if it can read private keys with a begin marker that starts with

  • "-----BEGIN PRIVATE", "-----BEGIN ENCRYPTED" (PEM, PKCS#8)
  • "-----BEGIN RSA", "-----BEGIN DSA", or "-----BEGIN EC" (older OpenSsh)
  • "-----BEGIN SSH" (apparently some ssh implementation by F-Secure)

However, if ssh-keygen from OpenSsh is called with -o, it'll create a private key file with a begin marker "-----BEGIN OPENSSH PRIVATE KEY-----". JSch cannot read that. :-(

Check if you have any default private key that has such a begin marker. If so, you have three options:

  • You could convert it to one of the other formats (should be possible via ssh-keygen) to circumvent the problem.
  • Since the problem does not occur on all computers, I guess that default key is not the one you want to use for BitBucket. (You don't seem to have it on your MacBook.) So maybe it's an option to remove it from the Eclipse preferences, if it's there, or delete it altogether (if you don't need it for something else).
  • Or rename it to some non-standard name like "id_rsa_forwhatever" and have an entry in the ssh config file for the host(s) it is to be used with with an "IdentityFile ~/.ssh/id_rsa_forwhatever" line. Then JSch should not load it (unless you tried connecting to that host with EGit), but your command-line ssh could still use it.
  • Or set GIT_SSH to use an external ssh.

[Updated on: Mon, 22 October 2018 13:11]

Report message to a moderator

Re: Error loading the SSH2 private keys [message #1797079 is a reply to message #1796925] Wed, 24 October 2018 22:10 Go to previous messageGo to next message
Stefano Scaccabarozzi is currently offline Stefano ScaccabarozziFriend
Messages: 3
Registered: October 2018
Junior Member
Hello Thomas,

thank you! Your suggestions helped me in resolving the problem. Since I had generated the RSA key using the -o, the issue was caused by the first line in the private key ( "-----BEGIN OPENSSH PRIVATE KEY-----"). I re-generated the key without the -o and everything is working fine now.

Thanks again for your help,
Stefano

[Updated on: Wed, 24 October 2018 22:11]

Report message to a moderator

Re: Error loading the SSH2 private keys [message #1797510 is a reply to message #1796925] Thu, 01 November 2018 00:54 Go to previous messageGo to next message
Lukas Tegethoff is currently offline Lukas TegethoffFriend
Messages: 2
Registered: November 2018
Junior Member
Quote:
However, if ssh-keygen from OpenSsh is called with -o, it'll create a private key file with a begin marker "-----BEGIN OPENSSH PRIVATE KEY-----". JSch cannot read that. :-(


Actually, since Version 7.8, released 3 months ago, this format was made the new default behaviour when generating a new key pair with OpenSSH.

I only ran into this issue because my Laptop runs Arch and they have the latest version (7.9); Debian has it in their testing branch and since JSch looks to be somewhat dead (last activity looks like it was around August 2016), I think this could develop to be quite annoying in the future,

Maybe it's time for a new Eclipse Project :P

But seriously, I think there should at least be some kind of warning or message for users, I was pretty confused until I had time to actually look at the sources to figure out what was going on (I know it's my fault for using Arch, but still :P ).

Unfortunately, I can't post my sources with this message, since it's my first in the forums, if I can edit them, I will, otherwise I will make a separate reply.
Re: Error loading the SSH2 private keys [message #1797638 is a reply to message #1797510] Sat, 03 November 2018 09:56 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 175
Registered: August 2016
Senior Member
[quote title=Lukas Tegethoff wrote on Thu, 01 November 2018 00:54]Quote:
JSch looks to be somewhat dead (last activity looks like it was around August 2016), I think this could develop to be quite annoying in the future,

Maybe it's time for a new Eclipse Project :P

Indeed. It already is quite a nuisance. See Eclipse bugs 520927 and 540727. We're on it.
Re: Error loading the SSH2 private keys [message #1797656 is a reply to message #1797638] Sun, 04 November 2018 02:28 Go to previous messageGo to next message
Lukas Tegethoff is currently offline Lukas TegethoffFriend
Messages: 2
Registered: November 2018
Junior Member
Ahh, good to see you are one step ahead, thanks for the answer and your work!
Re: Error loading the SSH2 private keys [message #1798601 is a reply to message #1797656] Tue, 20 November 2018 21:55 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 175
Registered: August 2016
Senior Member
See https://www.eclipse.org/lists/jgit-dev/msg03709.html .
Re: Error loading the SSH2 private keys [message #1799197 is a reply to message #1798601] Sat, 01 December 2018 14:20 Go to previous messageGo to next message
Hank Birkdale is currently offline Hank BirkdaleFriend
Messages: 1
Registered: December 2018
Junior Member
I'm getting the same error running on a Macbook. Initially the keys did begin with "BEGIN OPPENSSH PRIVATE KEY", so I switched it to use the RSA keygen in Eclipse itself, thinking that would work. The key starts with "BEGIN RSA PRIVATE KEY" and am still getting the invalidkey error. I've tried to update eGit with no luck.
org.eclipse.jgit.api.errors.TransportException: git@github.com:lendkey/Automation.git: invalid privatekey: [B@114f19fc
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:lendkey/Automation.git: invalid privatekey: [B@114f19fc
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:183)
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)
Re: Error loading the SSH2 private keys [message #1799270 is a reply to message #1799197] Mon, 03 December 2018 18:45 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 175
Registered: August 2016
Senior Member
Anything more in the stack trace or in the error log? Which Eclipse and EGit version? And are you sure it uses the RSA key you created in Eclipse, and not by chance still the new-style OpenSSH key (for instance, because it is still set in ~/.ssh/config)? You could also try to convert the new-style OpenSSH key ("BEGIN OPENSSH PRIVATE KEY") to PEM format.
Re: Error loading the SSH2 private keys [message #1799271 is a reply to message #1799270] Mon, 03 December 2018 18:47 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 175
Registered: August 2016
Senior Member
Or you could try installing EGit nightly and switching to the new alternate SSH implementation ("Ssh client: Apache MINA sshd" in Preferences->Team->Git).
Re: Error loading the SSH2 private keys [message #1799851 is a reply to message #1799271] Fri, 14 December 2018 20:01 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1106
Registered: July 2009
Senior Member
The next EGit release 5.2 which will be published next week comes with the new Apache Mina sshd based implementation.
See https://wiki.eclipse.org/EGit/New_and_Noteworthy/5.2#New_SSH_Library
Previous Topic:JGit - ancestry-path
Next Topic:Git hooks in eclipse
Goto Forum:
  


Current Time: Fri Dec 13 13:10:02 GMT 2019

Powered by FUDForum. Page generated in 0.01920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top