我需要从 hadoop 集群连接到 sftp 服务器。我想知道是否有办法从 hdfs 中存储的私钥加载身份。实际上,JSch 对象似乎只接受本地路径:
try {
String privateKeyPath = "hdfs://namenode:8020/path/to/privatekey"; // need this one to be an hdfs path
JSch jsch = new JSch();
jsch.addIdentity(privateKeyPath);
// [..]
}
catch (Exception ex) {
// [..]
}
有什么想法吗?
最佳答案
感谢@Martin Prikryl 的回答,解决如下:
// Get sftp private/public key for JSch identity
FSDataInputStream fis = fs.open(privateKeyPath);
byte[] privateKeyBytes = IOUtils.toByteArray(fis);
fis = fs.open(publicKeyPath);
byte[] publicKeyBytes = IOUtils.toByteArray(fis);
fis.close();
JSch jsch = new JSch();
String idName = "ksftp";
byte[] passphrase = null;
jsch.addIdentity(idName, privateKeyBytes, publicKeyBytes, passphrase);
关于java - JSch:从存储在 hdfs 上的私钥添加身份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50859100/