Код: Выделить всё
org.apache.sshd.common.SshException: No more authentication methods available org.apache.sshd.common.future.AbstractSshFuture.verifyResult(AbstractSshFuture.java:141) ~[sshd-common-2.14.0.jar:2.14.0] org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:56) ~[sshd-core-2.14.0.jar:2.14.0] org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:35) ~[sshd-core-2.14.0.jar:2.14.0] org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:43) ~[sshd-common-2.14.0.jar:2.14.0]
Код: Выделить всё
try (SshClient sshClient = SshClient.setUpDefaultClient()) {
sshClient.start();
try (ClientSession session =
sshClient.connect(user, host, port).verify(ftpTimeOutInSeconds * 1000L).getSession()) {
Path privateKeyPath = Paths.get(System.getProperty("java.io.tmpdir"), "key.pem");
FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(privateKeyPath);
Iterable keyPairs = fileKeyPairProvider.loadKeys(session);
if (keyPairs.iterator().hasNext()) {
session.addPublicKeyIdentity(keyPairs.iterator().next());
}
session.auth().verify(ftpTimeOutInSeconds * 1000L);
LOGGER.info("Session authenticated successfully!");
}
} catch (IOException e) {
LOGGER.error("I/O Exception occurred: " + e.getMessage());
} catch (Exception e) {
LOGGER.error("General Exception occurred: " + e.getMessage());
}
Код: Выделить всё
session.auth().verify(ftpTimeOutInSeconds * 1000L);
Код: Выделить всё
JSch jsch = new JSch();
Session session1 = null;
try {
Path privateKeyPath = Paths.get(System.getProperty("java.io.tmpdir"), "key.pem");
jsch.addIdentity(privateKeyPath.toString());
session1 = jsch.getSession(user, host, port);
session1.setTimeout(ftpTimeOutInSeconds * 1000);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session1.setConfig(config);
session1.connect();
LOGGER.info("Connected and authenticated successfully!");
} catch (JSchException e) {
LOGGER.error("JSch Exception occurred: " + e.getMessage());
} finally {
if (session1 != null && session1.isConnected()) {
session1.disconnect();
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -mina-sshd