1 year ago
#152673
vivi
Apache mina sshd client: jump server with password authentication
I am trying to implement a ssh client based on MINA sshd communicating with the end server via a ssh jump.
based on the documentation (https://github.com/apache/mina-sshd/blob/master/docs/internals.md#ssh-jumps) and other information found on the Internet, my code is looking like this.
SshClient client = SshClient.setUpDefaultClient();
client.setHostConfigEntryResolver(
HostConfigEntry.toHostConfigEntryResolver(
Arrays.asList(
new HostConfigEntry("server", "end-server", 22, "user1", "proxy"),
new HostConfigEntry("proxy", "proxy-server", 22, "user2"))));
client.start();
try (ClientSession session = client.connect("server").verify(defaultTimeout).getSession()) {
session.addPasswordIdentity("password1"); // password for the end-server
session.auth().verify(defaultTimeout);
try (ByteArrayOutputStream responseStream = new ByteArrayOutputStream();
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
ClientChannel channel = session.createExecChannel("pwd"))
{
channel.setOut(responseStream);
channel.setErr(errorStream);
try {
channel.open().verify(defaultTimeout);
try (OutputStream pipedIn = channel.getInvertedIn()) {
pipedIn.write("dir".getBytes());
pipedIn.flush();
}
channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), defaultTimeout);
String error = errorStream.toString();
if (!error.isEmpty()) {
throw new Exception(error);
}
System.out.println(responseStream);
} finally {
channel.close(false);
}
}
}
This implementation is working fine provided that the authentication to the proxy is via key authentication and the end server uses password authentication.
The problem is that in reality the jump server I am using only offers password authentication and I do not find the way to provide its credential.
How can I provide the jump server credential ?
Thanks!
java
apache-mina
apache-sshd
0 Answers
Your Answer