Serega2780 commented on issue #745:
URL: https://github.com/apache/mina-sshd/issues/745#issuecomment-2839251279
> This is not actionable. How about posting your client-side code?
` public void connect(String login, String password, String host)
throws IOException {
SshClient client = SshClient.setUpDefaultClient();
client.setKeyExchangeFactories(NamedFactory.setUpTransformedFactories(
false,
BuiltinDHFactories.VALUES,
ClientBuilder.DH2KEX
));
client.setSignatureFactories(new
ArrayList<>(BuiltinSignatures.VALUES));
client.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
client.start();
log.info("Start SSH connection for login {} device {} port {}",
login, host, port);
try (ClientSession session =
client.connect(vaultResponseDto.getLogin(), host, port)
.verify(connectionTimeout).getSession()) {
session.addPasswordIdentity(vaultResponseDto.getPassword());
session.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
session.auth().verify(connectionTimeout);
session.setSessionHeartbeat(SessionHeartbeatController.HeartbeatType.IGNORE,
Duration.of(100, TimeUnit.MILLISECONDS.toChronoUnit()));
log.info("SSH connection successful for login {} device {} port
{}",
vaultResponseDto.getLogin(), host, port);
try (ByteArrayOutputStream responseStream = new
ByteArrayOutputStream();
ClientChannel channel =
session.createExecChannel("interactive")) {
channel.setOut(responseStream);
try {
channel.open().verify(10, TimeUnit.SECONDS);
try (OutputStream pipedIn = channel.getInvertedIn()) {
pipedIn.write("show\n\r".getBytes());
pipedIn.flush();
}
var states = new
LinkedList<>(channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0L));
states.reversed().forEach(s -> log.info("STATE {}", s));
String responseString = new
String(responseStream.toByteArray());
log.info("RESULT SIZE {}", responseString.length());
log.info("EXIT STATUS {}", channel.getExitStatus());
} finally {
channel.close(false);
log.info("CHANNEL CLOSED");
}
}
return ;
} catch (org.apache.sshd.common.SshException e) {
if (NO_MORE_AUTH_METHODS_AVAILABLE.equals(e.getMessage())) {
log.info("Wrong credentials");
return ;
}
log.error("SSH connection error ", e);
throw new SshException(e);
} finally {
client.stop();
}
}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]