I use the program Eclipse for editing website files on a server. We recently beefed up security on the server by disabling password logins and instead only allow SSH login with an SSH key. But once we enabled that, I could no longer use Eclipse to SSH into the server. I started getting an error saying “Auth fail”.
First off, some back story on how I had previously setup the SSH key with the server. I generated the SSH key locally by using SSH key-gen command on my local machine. I then uploaded it to the server, like I described in my previous post (I followed my own instructions).
Up until that point, though, I had always used password authentication in Eclipse’s Remote System Explorer. So once we disabled password logins, Eclipse wouldn’t work for me anymore.
When I tried SSH’ing in with Eclipse I was getting the error
I followed these instructions to make sure Eclipse knew which SSH key to use, but the error didn’t go away.
This ancient forum post pointed me to some more debug info in Eclipse’s log file (Help > About > Installation Details : View Error Log). In there I saw the culprit:
!ENTRY org.eclipse.jsch.core 4 0 2020-12-11 11:27:14.207 !MESSAGE An error occurred loading the SSH2 private keys !STACK 0 com.jcraft.jsch.JSchException: invalid privatekey: [B@436797be 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:406) at com.jcraft.jsch.JSch.addIdentity(JSch.java:366) at org.eclipse.jsch.internal.core.Utils.loadPrivateKeys(Utils.java:108) at org.eclipse.jsch.internal.core.JSchCorePlugin.loadPrivateKeys(JSchCorePlugin.java:226) at org.eclipse.jsch.internal.core.JSchProvider.createSession(JSchProvider.java:46) at org.eclipse.rse.internal.connectorservice.ssh.SshConnectorService.createSession(SshConnectorService.java:112) at org.eclipse.rse.internal.connectorservice.ssh.SshConnectorService.internalConnect(SshConnectorService.java:182) at org.eclipse.rse.core.subsystems.AbstractConnectorService$1.run(AbstractConnectorService.java:504) at org.eclipse.rse.core.subsystems.AbstractConnectorService$SafeRunner.run(AbstractConnectorService.java:447) at org.eclipse.rse.core.subsystems.AbstractConnectorService.connect(AbstractConnectorService.java:511) at org.eclipse.rse.ui.operations.SystemFetchOperation.ensureConnected(SystemFetchOperation.java:311) at org.eclipse.rse.ui.operations.SystemFetchOperation.execute(SystemFetchOperation.java:375) at org.eclipse.rse.ui.operations.SystemFetchOperation.run(SystemFetchOperation.java:184) at org.eclipse.rse.ui.view.AbstractSystemViewAdapter.fetchDeferredChildren(AbstractSystemViewAdapter.java:2292) at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:219) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
I was like, “how dare you call my private key invalid! I’m using with other programs just fine!”
I then searched for that error which led me to an article that pointed out that SSH key-gen command, at some point, started producing SSH keys that Eclipse (or rather, its Java library that it uses) couldn’t understand.
The important takeaway
The root cause was discovered to be the ssh private key mismatch. The exception only happened for users with key of newer kind ed25519, which outputs this key header:
-----BEGIN OPENSSH PRIVATE KEY-----
instead of kind RSA:
-----BEGIN RSA PRIVATE KEY-----
regenerating an RSA key (Stack Overflow user Natan, https://stackoverflow.com/a/53783283/1493883
ssh-keygen -t rsa), made the exception go away.
So I needed a different SSH key.
So I copied my private and public keys, then used
ssh-keygen -f carbon60_id_rsa -m pem to convert the originals to this older style of SSH key. I then re-uploaded the public key to the server, and then Eclipse’s remote system explorer started working again.