修改路径:/etc/ssh下的sshd_config
在结尾添加: KexAlgorithms +diffie-hellman-group1-sha1
然后重启sshd:service sshd restart
如果还不行可以修改:ssh_config 也是添加 :KexAlgorithms +diffie-hellman-group1-sha1
java代码按下面方式编写:
Session session = null;
JSch jsch = new JSch();
try {
session = jsch.getSession(username, host, port);
session.setPassword(password);
session.setTimeout(5 * 60 * 1000);
session.setConfig("StrictHostKeyChecking", "no");//是否验证主机秘钥
Properties sshConfig = new Properties();
sshConfig.put("kex", "diffie-hellman-group1-sha1");
session.connect();
} catch (Exception e) {
throw new Exception("连接linux服务器时出错:" + e.getMessage());
}