只需尝试从Windows 10运行以下Java代码即可连接远程Linux服务器。
JSch jsch = new JSch();
Session session = jsch.getSession(username, host, port);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
但获得Error: com.jcraft.jsch.JSchException: Auth cancel
我可以从Putty连接同一台服务器。在其他一些posts中,建议使用setKnownHosts
方法但不确定如何使其正常工作。
JSch LOG (出于安全原因删除了几行): -
Connecting to xxx port xxx
Connection established
Remote version string: SSH-2.0-OpenSSH_5.3
Local version string: SSH-2.0-JSCH-0.1.54
...
...
aes256-ctr is not available.
aes192-ctr is not available.
aes256-cbc is not available.
aes192-cbc is not available.
CheckKexes: xxx
CheckSignatures: xxx
SSH_MSG_KEXINIT sent
SSH_MSG_KEXINIT received
...
...
SSH_MSG_KEXDH_INIT sent
expecting SSH_MSG_KEXDH_REPLY
ssh_rsa_verify: signature true
Permanently added xxx (RSA) to the list of known hosts.
SSH_MSG_NEWKEYS sent
SSH_MSG_NEWKEYS received
SSH_MSG_SERVICE_REQUEST sent
SSH_MSG_SERVICE_ACCEPT received
Authentications that can continue: keyboard-interactive,password
Next authentication method: keyboard-interactive
Disconnecting from xxx port xxx