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

Still throws JSchException: invalid privatekey #12

Closed
wangchenOS opened this issue Jul 23, 2020 · 4 comments
Closed

Still throws JSchException: invalid privatekey #12

wangchenOS opened this issue Jul 23, 2020 · 4 comments

Comments

@wangchenOS
Copy link

wangchenOS commented Jul 23, 2020

I run my program using this version to connect remote host by private id_rsa file on mac ,but program run error throws this exception:

com.jcraft.jsch.JSchException: invalid privatekey: [B@9807454
at com.jcraft.jsch.KeyPair.load(KeyPair.java:666)
at com.jcraft.jsch.KeyPair.load(KeyPair.java:563)
at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)
at com.jcraft.jsch.JSch.addIdentity(JSch.java:425)
at com.jcraft.jsch.JSch.addIdentity(JSch.java:406)

image

ssh version:
OpenSSH_7.9p1, LibreSSL 2.7.3
The id_rsa file is generated by the command " ssh-keygen -t rsa" , so current version does not support this encryption algorithm ?

@mwiede
Copy link
Owner

mwiede commented Jul 23, 2020

you have the same issue as described in https://stackoverflow.com/questions/53134212/invalid-privatekey-when-using-jsch

your ssh version is >= 7.8, so the generated key has OPENSSH format, which has -----BEGIN OPENSSH PRIVATE KEY----- in the first line of the private key. This type of key is not supported by Jsch as of now.

Please generate the key using ssh-keygen -t rsa -m PEM, which triggers ssh-keygen to use legacy key format. Check that you have -----BEGIN RSA PRIVATE KEY----- in the first line of the private key.

@wangchenOS
Copy link
Author

Got it

@raghulkrishna
Copy link

is this supported now ? i am getting the error

com.jcraft.jsch.JSchException: invalid privatekey: [B@49e202ad

@hmmmk
Copy link

hmmmk commented Feb 8, 2025

is this supported now ? i am getting the error

com.jcraft.jsch.JSchException: invalid privatekey: [B@49e202ad

Same question here. I have the same error with openssh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants