Apache SSHD客户端获取服务器公钥

Jan*_*tze 5 java ssh openssh apache-mina sshd

我试图获取服务器的公钥.这是我试过的:

val serverKey = sshClient.connect("dyn mem", "localhost", "2222")
  .verify()
  .getSession()
  .getKex()
  .getServerKey()
Run Code Online (Sandbox Code Playgroud)

问题是得到的结果getServerKey()是null ...

如何使用Apache SSHD客户端获取SSH服务器的公钥.

df7*_*899 2

connect()后续的密钥交换都是异步操作,因此需要等待几次。例如:

        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();
Run Code Online (Sandbox Code Playgroud)