I am trying to get the public key of a server. This is what I tried:
val serverKey = sshClient.connect("dyn mem", "localhost", "2222")
.verify()
.getSession()
.getKex()
.getServerKey()
The problem is get the result of getServerKey()
is null...
How can I get the public key of a SSH server with the Apache SSHD client.
Both connect()
, and the subsequent key exchange are async operations, so a couple of waits are needed. E.g. :
ConnectFuture connectFuture = client.connect(username, host, 22);
connectFuture.await(5000);
ClientSession session = connectFuture.getSession();
session.waitFor(Arrays.asList(ClientSessionEvent.WAIT_AUTH), 5000);
session.getKex().getServerKey();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With