JSch:从存储在hdfs上的私钥获取addIdentity [英] JSch: addIdentity from private key stored on hdfs
本文介绍了JSch:从存储在hdfs上的私钥获取addIdentity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从hadoop集群连接到sftp服务器.我想知道是否有一种方法可以从存储在hdfs中的私钥加载身份.实际上,似乎JSch对象仅接受本地路径:
I need to connect to an sftp server from an hadoop cluster. I would like to know if there is a way to load an identity from a private key stored in hdfs. Actually it seems that the JSch object accepts only a local path:
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的回答,解决方法如下:
Thanks to @Martin Prikryl answer, solved as following:
// 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);
这篇关于JSch:从存储在hdfs上的私钥获取addIdentity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文