Java – jsch – invalid private key

I am running JDK 1.7 & Windows 7 using NetBeans 7.2

JSch jsch = new JSch();

Session session = null;

try {

    jsch.addIdentity("D:\\TEMP\\key.ppk");

    session = jsch.getSession("tiabscp","ssiw.support.qvalent.com",22);
    session.setConfig("StrictHostKeyChecking","no");
    //session.setPassword("");
    session.connect();
    Channel channel = session.openChannel("sftp");
    System.out.println("Getting connected");
    channel.connect();
    System.out.println("connected successfully");
    ChannelSftp sftpChannel = (ChannelSftp) channel;
    sftpChannel.get("remotefile.txt","localfile.txt");
    sftpChannel.exit();
    session.disconnect();
}catch (JSchException e) {

    e.printStackTrace();

}catch (SftpException e) {

    e.printStackTrace();
}

Solution

I guess your key is not in openssh key file format Jsch wants the private key to be in openssh format

You can use putty to convert your private key to openssh. Follow the steps to describe here:

>Press load, and then select the puttygen of the created private key. > Enter the password to load the key. > From the conversion menu, select export openssh key > Save private key

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>