Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid private key when opening SSH tunnel with JSch

With JSch I'm calling addIdentity() to add a private key and getSession() to open an SSH tunnel.

When running this code locally on my Windows machine the opening of the tunnel is working.

However when running that same code with the same private key on our CI the following error occurs:

2016-12-07 01:01:32 ERROR SSHConnector:25 - invalid privatekey: [B@4bb4de6a
com.jcraft.jsch.JSchException: invalid privatekey: [B@4bb4de6a
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:747)
    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:408)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:389)

The private key looks something like this:

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
XXXXXXXXXXXXXXXXXXX
Private-Lines: 14
XXXXXXXXXXXXXXXXXX
Private-MAC: XXXXXXXXXXXXXXXX

What could be the error here?

like image 779
Harold L. Brown Avatar asked Nov 05 '25 05:11

Harold L. Brown


1 Answers

My problem was solved by using pem file instead of ppk.

pem file is in OpenSSH format that com.jcraft.jsch.JSch jar requires

like image 123
Rishab Avatar answered Nov 06 '25 21:11

Rishab