복붙노트

[HADOOP] JSch : hdfs에 저장된 개인 키의 addIdentity [duplicate]

HADOOP

JSch : hdfs에 저장된 개인 키의 addIdentity [duplicate]

hadoop 클러스터에서 sftp 서버에 연결해야합니다. hdfs에 저장된 개인 키에서 ID를로드하는 방법이 있는지 알고 싶습니다. 사실 그것은 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) {
    // [..]
}

어떤 생각?

해결법

  1. ==============================

    1.@ 마틴 Prikryl 대답 덕분에, 다음과 같은 해결 :

    @ 마틴 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);
    
  2. from https://stackoverflow.com/questions/50859100/jsch-addidentity-from-private-key-stored-on-hdfs by cc-by-sa and MIT license