Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache SSHD client get server public key

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.

like image 530
Jan Wytze Avatar asked Oct 28 '22 11:10

Jan Wytze


1 Answers

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();
like image 61
df778899 Avatar answered Nov 11 '22 14:11

df778899