gpt4 book ai didi

java - JSch 异常 : Algorithm negotiation fail diffie-hellman-group14-sha1

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:31:07 29 4
gpt4 key购买 nike

我知道这个问题已经被问过几次了,但我已经尝试了很多已经给出的可接受的解决方案。

我正在使用 JSch 创建一个简单的 SSH 隧道。我在日志中不断收到此错误消息:

INFO: diffie-hellman-group14-sha1 is not available.

我已经将 Java 无限策略文件添加到正确的文件夹中,并将该算法添加到 sshd_config 文件中的 KexAlgorithms 部分。以下是完整的日志分割。

INFO: Connecting to xx.xx.xxx.xxx port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_6.8
INFO: Local version string: SSH-2.0-JSCH-0.1.50
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192- cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: CheckKexes: diffie-hellman-group14-sha1
INFO: diffie-hellman-group14-sha1 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
INFO: kex: server: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
INFO: kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
INFO: kex: server: none,zlib@openssh.com
INFO: kex: server: none,zlib@openssh.com
INFO: kex: server:
INFO: kex: server:
INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
INFO: kex: client: ssh-rsa,ssh-dss
INFO: kex: client: aes256-cbc
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc
INFO: kex: client: hmac-sha2-256
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 xx.xx.xxx.xxx port 22
com.jcraft.jsch.JSchException: Algorithm negotiation fail

最佳答案

您的客户端和服务器不共享通用的 KEX 算法:

INFO: kex: server: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1

INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1

如您所见,在对方的列表中找不到任何一方支持的算法。您可以通过以下两种方式之一向您的客户端添加对其他 KEX 算法的支持:

  1. 将 JSch 升级到最新版本 (0.1.52) 以自动启用对 sha256 的支持。
  2. 如果您受困于 0.1.51,您可以通过编程方式启用 sha256:

    JSch shell = new JSch();
    Properties config = new Properties();
    config.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
    config.put("StrictHostKeyChecking", "no");

    然后创建 session 并设置配置:

    Session session = ...
    session.setConfig(config);

关于java - JSch 异常 : Algorithm negotiation fail diffie-hellman-group14-sha1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30077327/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com