Skip to content

Commit

Permalink
cachecloud 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
githubname1024 committed Aug 5, 2024
1 parent 0f7e0a0 commit 8d78286
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cachecloud-web/src/main/java/com/sohu/cache/ssh/SSHClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sohu.cache.ssh;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.auth.password.PasswordIdentityProvider;
Expand All @@ -11,6 +12,7 @@
import org.apache.sshd.common.util.security.SecurityUtils;

import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
Expand All @@ -23,6 +25,7 @@
* @Auther: yongfeigao
* @Date: 2023/10/23
*/
@Slf4j
@Data
public class SSHClient {

Expand Down Expand Up @@ -62,9 +65,13 @@ private SshClient buildSshClient() {
}

private void setAuthByKey(SshClient client) throws GeneralSecurityException, IOException {
KeyPairResourceLoader loader = SecurityUtils.getKeyPairResourceParser();
Collection<KeyPair> keys = loader.loadKeyPairs(null, Paths.get(privateKeyPath), null);
client.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys));
try{
KeyPairResourceLoader loader = SecurityUtils.getKeyPairResourceParser();
Collection<KeyPair> keys = loader.loadKeyPairs(null, Paths.get(privateKeyPath), null);
client.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys));
}catch (FileSystemException e){
log.error("setAuthByKey error, please check ssh type and key path and key. ", e);
}
}

/**
Expand Down

0 comments on commit 8d78286

Please sign in to comment.