JSch how to use with PuTTY private key

扶醉桌前 提交于 2019-12-01 01:04:38

Make sure you use the latest version of JSch, as older versions do not support the .ppk format natively.

Code Snippet for connection using PuTTy private Key (.ppk)

JSch jsch=new JSch();
jsch.setKnownHosts("~\.ssh\know_hosts");
jsch.addIdentity("~\sshkey.ppk");
Session session=jsch.getSession("ec2-user", "54.12.11.90", 22);
session.setConfig("PreferredAuthentications", "publickey");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel=session.openChannel("shell");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect(3*1000);

Have used 0.1.54 version of Jsch

        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.54</version>
        </dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!