Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSch consider private key ivalid if generated with OpenSSH 7.8 and higher #567

Open
bondars95 opened this issue Aug 29, 2019 · 1 comment
Labels

Comments

@bondars95
Copy link

**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 (ssh-keygen -t rsa), made the exception go away.

If you have OpenSSH 7.8 and above you might need to add -m PEM to the generation command: ssh-keygen -t rsa -m PEM**

When using private key generated by OpenSSSh 7.8 error below occurs.

org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "****".
at org.apache.commons.vfs2.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:107) ~[commons-vfs2-2.0.jar:2.0]
at org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider.getFileSystem(AbstractOriginatingFileProvider.java:103) ~[commons-vfs2-2.0.jar:2.0]
at org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:81) ~[commons-vfs2-2.0.jar:2.0]
at org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:65) ~[commons-vfs2-2.0.jar:2.0]
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:693) ~[commons-vfs2-2.0.jar:2.0]
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:621) ~[commons-vfs2-2.0.jar:2.0]
at pl.otros.vfs.browser.util.VFSUtils.resolveFileObject(VFSUtils.java:346) ~[OtrosVfsBrowser.jar:na]
at pl.otros.vfs.browser.util.VFSUtils.resolveFileObject(VFSUtils.java:310) ~[OtrosVfsBrowser.jar:na]
at pl.otros.vfs.browser.VfsBrowser.goToUrl(VfsBrowser.java:128) ~[OtrosVfsBrowser.jar:na]
at pl.otros.vfs.browser.actions.OpenSelectedFavorite.performLongOperation(OpenSelectedFavorite.java:41) ~[OtrosVfsBrowser.jar:na]
at pl.otros.vfs.browser.actions.BaseNavigateAction$1.doInBackground(BaseNavigateAction.java:75) ~[OtrosVfsBrowser.jar:na]
at pl.otros.vfs.browser.actions.BaseNavigateAction$1.doInBackground(BaseNavigateAction.java:65) ~[OtrosVfsBrowser.jar:na]
at java.desktop/javax.swing.SwingWorker$1.call(SwingWorker.java:304) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.desktop/javax.swing.SwingWorker.run(SwingWorker.java:343) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: org.apache.commons.vfs2.FileSystemException: Could not load private key from "/Users/sebo/.ssh/backup/id_rsa".
at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:110) ~[commons-vfs2-2.0.jar:2.0]
at org.apache.commons.vfs2.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:96) ~[commons-vfs2-2.0.jar:2.0]
... 17 common frames omitted
Caused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@20345904
at com.jcraft.jsch.KeyPair.load(KeyPair.java:664) ~[jsch-0.1.55.jar:na]
at com.jcraft.jsch.KeyPair.load(KeyPair.java:561) ~[jsch-0.1.55.jar:na]
at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40) ~[jsch-0.1.55.jar:na]
at com.jcraft.jsch.JSch.addIdentity(JSch.java:406) ~[jsch-0.1.55.jar:na]
at com.jcraft.jsch.JSch.addIdentity(JSch.java:366) ~[jsch-0.1.55.jar:na]
at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:106) ~[commons-vfs2-2.0.jar:2.0]
... 18 common frames omitted

@svennissel
Copy link
Collaborator

With #582 we use a newer library to connect via ssh. I hope it fixed it. Please try the upcoming version 1.4.16

@svennissel svennissel added the bug label Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants