From d6738d635c4d14794818d6fd361bc9377e32130d Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 9 Sep 2021 23:46:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20SSH=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=20keyPassword=20?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于 mina-ssh 的设计问题, 如果手动设置 KeyIdentityProvider, 则 SshClient 中的 FilePasswordProvider 将对此无效(SshClient 的 FilePasswordProvider 只会对默认密钥路径 "~/id_rsa" 起作用), keyPassword 应直接在 FileKeyPairProvider 设置. --- .../lamgc/oracle/sentry/oci/compute/ssh/InstanceSsh.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/lamgc/oracle/sentry/oci/compute/ssh/InstanceSsh.java b/src/main/java/net/lamgc/oracle/sentry/oci/compute/ssh/InstanceSsh.java index 9cfd37a..5d2a494 100644 --- a/src/main/java/net/lamgc/oracle/sentry/oci/compute/ssh/InstanceSsh.java +++ b/src/main/java/net/lamgc/oracle/sentry/oci/compute/ssh/InstanceSsh.java @@ -44,10 +44,12 @@ public class InstanceSsh implements AutoCloseable { sshClient.setForwardingFilter(Constants.instance.getForwardingFilter()); sshClient.setServerKeyVerifier(new OracleInstanceServerKeyVerifier(instance, authInfo)); if (authInfo instanceof PublicKeyAuthInfo info) { - sshClient.setKeyIdentityProvider(new FileKeyPairProvider(info.getPrivateKeyPath().toPath())); + FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(info.getPrivateKeyPath().toPath()); if (!Strings.isNullOrEmpty(info.getKeyPassword())) { - sshClient.setFilePasswordProvider(FilePasswordProvider.of(info.getKeyPassword())); + fileKeyPairProvider.setPasswordFinder(FilePasswordProvider.of(info.getKeyPassword())); + log.info("已设置密钥解密密码."); } + sshClient.setKeyIdentityProvider(fileKeyPairProvider); } else if (authInfo instanceof PasswordAuthInfo info) { sshClient.addPasswordIdentity(info.getPassword()); } else {