JSch連接SSH問題Exception:Algorithm negotiation fail


自動安裝部署工具ideploy,使用ssh連接主機並部署業務 。操作系統SUSE11SP4升級到SUSE12后,出現下列報錯: 

JSch連接SSH問題Exception:Algorithm negotiation fail[SSH] Exception:Algorithm negotiation fail 

/app/aideploy/deploy_xx/xml/deploy-stop.xml:135: The following error occurred while executing this line:
/app/aideploy/deploy_xx/xml/deploy-stop.xml:141: com.jcraft.jsch.JSchException: Algorithm negotiation fail
at com.jcraft.jsch.Session.receive_kexinit(Session.java:582)
at com.jcraft.jsch.Session.connect(Session.java:320)
at com.jcraft.jsch.Session.connect(Session.java:183)
at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:225)
at org.apache.tools.ant.taskdefs.optional.ssh.SSHExec.execute(SSHExec.java:236)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)


原因分析: 操作系統升級時,sshd版本對應也進行了升級,ssh在6.7版本以后,對一些加密算法不支持,需要手動添加。
OpenSSH和 JSch支持的交換算法不同,需要一方打開另一方支持的交換算法。 

查看ssh版本: ssh -V  

OpenSSH enables only the following key exchange algorithms by default: 
- curve25519-sha256@libssh.org 
- ecdh-sha2-nistp256 
- ecdh-sha2-nistp384 
- ecdh-sha2-nistp521 
- diffie-hellman-group-exchange-sha256 
- diffie-hellman-group14-sha1 

Where as JSch claims to support these algorithms for key exchange: 
- diffie-hellman-group-exchange-sha1 
- diffie-hellman-group1-sha1 
解決辦法: 
在SSH的配置文件 
/etc/ssh/sshd_config 
增加以下兩行,讓SSH支持相應的算法和MACs 


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 

MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com,hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96 
完成后重啟SSH即可解決問題


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM