【问题标题】:Getting Algorithm negotiation fail while trying to connect to sftp server using Jsch in java [duplicate]尝试在java中使用Jsch连接到sftp服务器时获取算法协商失败[重复]
【发布时间】:2017-12-13 17:46:48
【问题描述】:

我正在尝试使用以下代码(之前运行良好)与 SFTP 服务器建立连接,但最近遇到了如下提供的错误日志 -

信息 - 我正在使用以下版本

  • Java 版本“1.8.0_101”
  • Java(TM) SE 运行时环境(内部版本 1.8.0_101-b13)
  • JSch - 0.1.54
  • Junit - 4.12

我正在使用下面的代码 -

JSch jsch = new JSch();

Properties configuration = new Properties();
configuration.put("cipher.s2c", 
                   "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc");
configuration.put("cipher.c2s",
                   "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc");
configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");

Session session = jsch.getSession(user , host, port);
session.setPassword(pwd);
session.setConfig(configuration);

System.out.println("------------------>Establishing Connection...");
session.connect();
System.out.println("------------------>Connection established.");
System.out.println("------------------>Creating SFTP Channel.");
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("------------------>SFTP Channel created.");

预期 - 应该成功连接到服务器

  • 注意 - 我尝试在此处包含其他各种帖子中描述的所有配置方法,但没有任何效果。

实际 - 出现以下错误 -

    com.jcraft.jsch.JSchException: Algorithm negotiation fail
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:590)
    at com.jcraft.jsch.Session.connect(Session.java:320)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at FunctionLib.StoreAllRecordsFromLOCAL_IntoRequestList_Test(FunctionLib.java:38)
    at TestJunit.testConnectivity(TestJunit.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

日志文件:

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: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group14-sha256@ssh.com,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
INFO: kex: server: ssh-rsa,ssh-rsa-sha256@ssh.com
INFO: kex: server: aes256-cbc,seed-cbc@ssh.com,crypticore128@ssh.com
INFO: kex: server: aes256-cbc,seed-cbc@ssh.com,crypticore128@ssh.com
INFO: kex: server: hmac-sha1,hmac-md5,crypticore-mac@ssh.com
INFO: kex: server: hmac-sha1,hmac-md5,crypticore-mac@ssh.com
INFO: kex: server: none,zlib
INFO: kex: server: none,zlib
INFO: kex: server: 
INFO: kex: server: 
INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
INFO: kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
INFO: kex: client: none
INFO: kex: client: none
INFO: kex: client: 
INFO: kex: client: 
INFO: Disconnecting from 10.92.155.57 port 22

使用Wifi运行时的日志-(连接建立成功)-

Dec 12, 2017 6:14:35 PM FunctionLib$MyJSchLogger log
INFO: Connecting to 10.92.155.6 port 22
Dec 12, 2017 6:14:35 PM FunctionLib$MyJSchLogger log
INFO: Connection established
Dec 12, 2017 6:14:35 PM FunctionLib$MyJSchLogger log
INFO: Remote version string: SSH-2.0-6.4.10.264 SSH Tectia Server
Dec 12, 2017 6:14:35 PM FunctionLib$MyJSchLogger log
INFO: Local version string: SSH-2.0-JSCH-0.1.54
Dec 12, 2017 6:14:35 PM FunctionLib$MyJSchLogger log
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
Dec 12, 2017 6:14:36 PM FunctionLib$MyJSchLogger log
INFO: aes256-ctr is not available.
Dec 12, 2017 6:14:36 PM FunctionLib$MyJSchLogger log
INFO: aes192-ctr is not available.
Dec 12, 2017 6:14:36 PM FunctionLib$MyJSchLogger log
INFO: aes256-cbc is not available.
Dec 12, 2017 6:14:36 PM FunctionLib$MyJSchLogger log
INFO: aes192-cbc is not available.
Dec 12, 2017 6:14:36 PM FunctionLib$MyJSchLogger log
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_KEXINIT sent
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_KEXINIT received
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group14-sha256@ssh.com,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: ssh-rsa,ssh-rsa-sha256@ssh.com
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: crypticore128@ssh.com,aes128-cbc,aes128-ctr,aes192-cbc,aes192-ctr,aes256-cbc,aes256-ctr,3des-cbc
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: crypticore128@ssh.com,aes128-cbc,aes128-ctr,aes192-cbc,aes192-ctr,aes256-cbc,aes256-ctr,3des-cbc
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: crypticore-mac@ssh.com,hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha256-2@ssh.com,hmac-sha224@ssh.com,hmac-sha256@ssh.com,hmac-sha384@ssh.com,hmac-sha2-512,hmac-sha512@ssh.com
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: crypticore-mac@ssh.com,hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha256-2@ssh.com,hmac-sha224@ssh.com,hmac-sha256@ssh.com,hmac-sha384@ssh.com,hmac-sha2-512,hmac-sha512@ssh.com
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: none,zlib
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: none,zlib
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: 
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server: 
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: none
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: none
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: 
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client: 
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: server->client aes128-ctr hmac-sha1 none
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: kex: client->server aes128-ctr hmac-sha1 none
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_KEXDH_INIT sent
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: expecting SSH_MSG_KEXDH_REPLY
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: ssh_rsa_verify: signature true
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
WARNING: Permanently added '10.92.155.6' (RSA) to the list of known hosts.
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_NEWKEYS sent
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_NEWKEYS received
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_SERVICE_REQUEST sent
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_SERVICE_ACCEPT received
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: Authentications that can continue: publickey,keyboard-interactive,password
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: Next authentication method: publickey
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: Authentications that can continue: password
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: Next authentication method: password
Dec 12, 2017 6:14:37 PM FunctionLib$MyJSchLogger log
INFO: Authentication succeeded (password).

使用 LAN 运行时的日志 - (未建立连接) -

Dec 12, 2017 6:12:36 PM FunctionLib$MyJSchLogger log
INFO: Connecting to 10.92.155.6 port 22
Dec 12, 2017 6:12:36 PM FunctionLib$MyJSchLogger log
INFO: Connection established
Dec 12, 2017 6:12:36 PM FunctionLib$MyJSchLogger log
INFO: Remote version string: SSH-2.0-6.4.10.264 SSH Tectia Server
Dec 12, 2017 6:12:36 PM FunctionLib$MyJSchLogger log
INFO: Local version string: SSH-2.0-JSCH-0.1.54
Dec 12, 2017 6:12:36 PM FunctionLib$MyJSchLogger log
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
Dec 12, 2017 6:12:37 PM FunctionLib$MyJSchLogger log
INFO: aes256-ctr is not available.
Dec 12, 2017 6:12:37 PM FunctionLib$MyJSchLogger log
INFO: aes192-ctr is not available.
Dec 12, 2017 6:12:37 PM FunctionLib$MyJSchLogger log
INFO: aes256-cbc is not available.
Dec 12, 2017 6:12:37 PM FunctionLib$MyJSchLogger log
INFO: aes192-cbc is not available.
Dec 12, 2017 6:12:37 PM FunctionLib$MyJSchLogger log
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_KEXINIT sent
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: SSH_MSG_KEXINIT received
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group14-sha256@ssh.com,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: ssh-rsa,ssh-rsa-sha256@ssh.com
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: aes256-cbc,seed-cbc@ssh.com,crypticore128@ssh.com
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: aes256-cbc,seed-cbc@ssh.com,crypticore128@ssh.com
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: hmac-sha1,hmac-md5,crypticore-mac@ssh.com
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: hmac-sha1,hmac-md5,crypticore-mac@ssh.com
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: none,zlib
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: none,zlib
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: 
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: server: 
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: none
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: none
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: 
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: kex: client: 
Dec 12, 2017 6:12:38 PM FunctionLib$MyJSchLogger log
INFO: Disconnecting from 10.92.155.6 port 22

【问题讨论】:

  • 嗨 Martin,我已经在使用 JSch 版本 - 0.1.54,还有其他最新版本吗?
  • Martin,能否请您告诉我如何获取您请求的日志?
  • 能否详细说明我需要在我的代码中的哪个位置放置这个 IN ?因为我面临来自 Eclipse 本身的多个错误。我需要将您的代码复制粘贴到单独的(.java)文件中还是如何?
  • 嗨,马丁,我已经根据您在下面提供的代码发布了我的发现。
  • 我已经添加了你的日志,所以不要再添加了。 + 您的问题是重复的,请点击上面的链接。请接受您的问题是重复的。

标签: java ssh jsch


【解决方案1】:

对于上述问题,我做了以下 -

更新了以下内容 - Java - 1.8.151 Eclipse - 氧气

安装 JDK 后,我使用此文件更新了文件夹 C:/ProgramFiles/Java/jre1.8.151/jre/lib/security/ 中的策略文件(local_policy.jar 和 US_export_policy.jar) --> Java Cryptography Extension (JCE) 无限强度管辖政策文件 8

下载文件的链接已在上述任一 cmets 中提及。

【讨论】:

  • 好的,我认为您对 LAN/wifi 做了一些事情。但是你没有,你做了我从一开始就建议你的事情,将你指向重复的问题。没有必要重新发布相同的解决方案。请接受您的问题是重复的,而不是重复答案。
猜你喜欢
  • 2015-08-09
  • 2017-02-12
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
  • 2016-05-08
相关资源
最近更新 更多