From 8d78286bf2e6791ac9f05f52db76eff1eeb0930e Mon Sep 17 00:00:00 2001 From: githubname1024 Date: Mon, 5 Aug 2024 10:49:02 +0800 Subject: [PATCH] cachecloud 3.3 --- .../src/main/java/com/sohu/cache/ssh/SSHClient.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cachecloud-web/src/main/java/com/sohu/cache/ssh/SSHClient.java b/cachecloud-web/src/main/java/com/sohu/cache/ssh/SSHClient.java index e60ede2b..001ae684 100644 --- a/cachecloud-web/src/main/java/com/sohu/cache/ssh/SSHClient.java +++ b/cachecloud-web/src/main/java/com/sohu/cache/ssh/SSHClient.java @@ -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; @@ -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; @@ -23,6 +25,7 @@ * @Auther: yongfeigao * @Date: 2023/10/23 */ +@Slf4j @Data public class SSHClient { @@ -62,9 +65,13 @@ private SshClient buildSshClient() { } private void setAuthByKey(SshClient client) throws GeneralSecurityException, IOException { - KeyPairResourceLoader loader = SecurityUtils.getKeyPairResourceParser(); - Collection keys = loader.loadKeyPairs(null, Paths.get(privateKeyPath), null); - client.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys)); + try{ + KeyPairResourceLoader loader = SecurityUtils.getKeyPairResourceParser(); + Collection 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); + } } /**