【发布时间】:2021-07-06 15:32:43
【问题描述】:
说明:
尝试向尝试访问 Netopeer2 服务器的应用程序发送请求,但出现问题并且密钥交换失败。在/etc/ssh/sshd_config 中提供了如何在服务器端配置它的解决方案,但我们希望它位于应用程序中的客户端。
应用程序使用 Apache MINA SSHD 建立连接 (GitHub)。默认情况下,某些算法被禁用。我们希望在下面的 Main 类中启用它们,以便能够与服务器交换 rsa-sha2-512, rsa-sha2-256。关于如何使用 Apache MINA SSHD 做到这一点的任何想法?
完整的错误信息是:
java.lang.IllegalStateException: Unable to negotiate key exchange for server host key algorithms
(client: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa,ssh-dss /
server: rsa-sha2-512,rsa-sha2-256)
引发错误的代码:
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import java.io.IOException;
public class Main{
public static void main(String[] args) {
SshClient client = SshClient.setUpDefaultClient();
client.start();
try {
ClientSession session = client.connect("root", "172.17.0.2", 830).verify(10000).getSession();
session.addPasswordIdentity("root");
session.auth().verify(9999);
// error 'Unable to negotiate key exchange for server host key algorithms' is thrown
}
catch (IOException e){
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java encryption sshd apache-mina