java - JSchException : Algorithm negotiation fail

标签 java encryption ssh sftp jsch

我正在尝试使用 JSch (0.1.44-1) 通过 ssh 连接到远程 sftp 服务器,但在 session.connect(); 期间,我收到此异常:

com.jcraft.jsch.JSchException: Algorithm negotiation fail at 
com.jcraft.jsch.Session.receive_kexinit(Session.java:529) at 
com.jcraft.jsch.Session.connect(Session.java:291) at com.jcraft.jsch.Session.connect(Session.java:154)
... 

来自 JSch 的日志:

INFO: Connecting to xx.xx.xx.xxport 22 
INFO: Connection established 
INFO: Remote version string: SSH-2.0-WeOnlyDo 2.0.6 
INFO: Local version string: SSH-2.0-JSCH-0.1.44 
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available. 
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available. 
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available. 
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received 
INFO: Disconnecting from xx.xx.xx.xx port 22 

我可以使用 linux sftp 命令登录远程服务器。我试图在互联网上寻找任何线索,但失败了。

Linux sftp 命令的调试输出:

OpenSSH_5.5p1-DAM_1.2, OpenSSL 0.9.8r 8 Feb 201

debug1: Reading configuration data /etc/DAM/ssh/ssh_config
debug1: Applying options for *
debug1: Applying options for *.*
debug1: Connecting to xx.xx.xx.xx [xx.xx.xx.xx] port 22.
debug1: Connection established.
debug1: identity file /**/spv_id_rsa.key type -1
debug1: identity file /**/spv_id_rsa.key-cert type -1
debug1: Remote protocol version 2.0, remote software version WeOnlyDo 2.0.6
debug1: no match: WeOnlyDo 2.0.6
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.5p1-DAM_1.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes256-cbc hmac-md5 none
debug1: kex: client->server aes256-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'xx.xx.xx.xx' is known and matches the RSA host key.
debug1: Found key in ~/.ssh/known_hosts:8
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /**/spv_id_rsa.key
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending subsystem: sftp
Connected to xx.xx.xx.xx.
sftp>

最佳答案

SSH 客户端和服务器在几个地方尝试并就通用实现达成一致。我知道的两个是加密和压缩。服务器和客户端生成可用选项列表,然后选择两个列表中的最佳可用选项。

如果列表中没有可接受的选项,则会失败并出现错误。我从这里的调试输出中猜测,但看起来唯一的加密服务器选项是“aes256-cbc hmac-md5 none”。

由于您的 Java 策略文件,JSch 不执行 hmac-md5 并且 aes256-cbc 被禁用。您可以尝试的两件事是...

  1. 要增加服务器上的可用加密库,请在客户端上安装不受限制的策略文件,从以下站点启用 aes256-cbc(确保显示已禁用的消息消失,这些策略文件非常容易安装在错误的 JVM 上):

    对于 JDK 1.6:http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html

    对于 JDK 1.7:http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

    对于 JDK 1.8:http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

  2. 或尝试禁用加密。

如果您可以访问服务器,第一个是理想的选择(相信我,aes128-cbc 已经足够加密),但第二个很容易快速测试理论。

关于java - JSchException : Algorithm negotiation fail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35152375/

相关文章:

javascript - 尝试通过 javascript 中的 .charCodeAt 将此凯撒密码 arr 重新转换为字符

linux - sshd_config 上允许用户,忘记设置 root

java - Glassfish 和 Tomcat 中 decodeBase64 的不同结果

ssh - OpenSSL 版本不匹配。针对 1000105f 构建,您有 10001080

ruby - 通过 ssh 调用远程命令,使用 Ruby,改进语法?

java - 直接在枚举中使用 Wicket 属性

java - Ibatis/Ibator - 如何使用示例类和条件正确编写 "complex"WHERE 子句?

java - 使用 java、thymeleaf 和 spring mvc 形成表格

java - 将 HTTP Request.login 与 JBoss/JAAS 一起使用

encryption - 密码学:混合 CBC 和 CTR?