我正在尝试获取服务器的公钥。这就是我所尝试的:
val serverKey = sshClient.connect("dyn mem", "localhost", "2222") .verify() .getSession() .getKex() .getServerKey()
问题是得到 getServerKey() 为空…
getServerKey()
如何使用apacheshd客户机获取ssh服务器的公钥。
两个 connect() ,后续的密钥交换是异步操作,因此需要等待两次。例如:
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();