Mar*_*iak 37 java encryption ssh sftp jsch
我试图通过ssh与JSch(0.1.44-1)连接到远程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)
...
Run Code Online (Sandbox Code Playgroud)
来自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
Run Code Online (Sandbox Code Playgroud)
我可以使用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>
Run Code Online (Sandbox Code Playgroud)
Pac*_*ace 28
SSH客户端和服务器有几个地方尝试并就共同实现达成一致.我知道的两个是加密和压缩.服务器和客户端生成可用选项列表,然后选择两个列表中的最佳可用选项.
如果列表中没有可接受的选项,则它会因您收到的错误而失败.我猜测这里的调试输出,但看起来加密的唯一服务器选项是"aes256-cbc hmac-md5 none".
由于您的Java策略文件,JSch不会执行hmac-md5和aes256-cbc.你可以尝试两件事......
要增加服务器上的可用加密库,请在客户端上安装不受限制的策略文件,从站点启用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
或尝试禁用加密.
第一个是理想的,如果你有权访问服务器(相信我aes128-cbc是充足的加密),但第二个很容易快速测试理论.
bru*_*dan 18
最后一个解决方案无需对服务器进行任何更改即可运行:
下载最新的jsch.jar,如Yvan建议:http: //sourceforge.net/projects/jsch/files/jsch.jar/jsch-0.1.52.jar工作正常
将下载的文件放在"...\JetBrains\PhpStorm 8.0.1\lib"中,并删除现有的jsch文件(对于PHPStorm 8,它是jsch-0.1.50.jar)
重启PHPStorm,它应该工作
对Webstorm使用相同的解决方案
由于 jsch 库似乎不再维护(最后一个版本于2018 年发布),上述答案都没有帮助我解决问题。
我最近遇到了同样的问题,因为服务器上的 OpenSSH 版本是 8.8,它已经告别了ssh-rsa算法。如果您搜索“jsch ssh-rsa”,您可能也会得到第一个结果: https: //www.matez.de/index.php/2020/06/22/the-future-of-jsch-没有-ssh-rsa/。
正如博客文章中所建议的,我应用了直接替换,并且无需对源代码进行任何更改即可工作。唯一需要的更改是将com.jcraft:jsch依赖项替换为com.github.mwiede:jsch.
代替:
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
和:
<dependency>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
希望这对未来的访客有所帮助。
将算法添加到RECEIVING服务器(要连接的服务器)的完整步骤。我假设这是一台Linux服务器。
sudo /etc/ssh/sshd_config
Run Code Online (Sandbox Code Playgroud)
将此添加到文件中(可以在末尾):
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
Run Code Online (Sandbox Code Playgroud)
然后重启SSH服务器:
sudo service sshd restart
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
97195 次 |
| 最近记录: |