public class FTP {
public static void main(String args[]){
JSch jsch = new JSch();
jsch.setKnownHosts("./known_hosts");
Path privateKeyPath = Paths.get("./id_dsa");
byte[] privateKey = Files.readAllBytes(privateKeyPath);
Path publicKeyPath = Paths.get("./id_dsa.pub");
byte[] publicKey = Files.readAllBytes(publicKeyPath);
// Either of the lines below work... Why?
// jsch.addIdentity("", privateKey, publicKey, null);
// or
jsch.addIdentity("", privateKey, null, null);
Session session = jsch.getSession("USER", "myHost.com", 22);
session.connect();
}
}
设置publicKey
到null
,不有所作为,我可以连接两种方式。这是为什么?JSCH addIdentity公钥参数不有所作为
看起来好像publicKey
没有被使用,所以为什么要把它首先传递给addIdentity
?
@Kenster no,id_dsa是一个私钥,id_dsa.pub是一个公钥。没有密码 – Kam
@Kenster我的问题并不是关于公钥的解释。如果我在jsch.addIdentity的第三个参数(不是第四个参数)中传递null,它仍然可以工作。 – Kam
@kenster我更新了代码。 – Kam