JSch如何使用PuTTY私钥

问题描述 投票:2回答:2

我正在尝试使用私有密钥配置的JSch。我使用PuTTYgen生成了公钥和私钥,但我不确定如何处理这两个文件。

哪个密钥(公共/私有)需要转移到服务器?

putty jsch private-key public-key
2个回答
3
投票

确保使用最新版本的JSch,因为旧版本本身不支持.ppk格式。


1
投票

使用PuTTy私钥(.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);

使用过Jsch的0.1.54版本

        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.54</version>
        </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.