简体   繁体   中英

com.jcraft.jsch.JSchException: Algorithm negotiation fail at com.jcraft.jsch.Session.receive_kexinit(Unknown Source)

I am trying to connect to one of my unix server, but it fails with the error above, can someone please help.

JSch jsch = new JSch();

java.util.Properties configuration = new java.util.Properties();
configuration.put("kex", "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");
configuration.put("StrictHostKeyChecking", "no");

Session session=jsch.getSession(user, host, 22);
session.setPassword(password);

session.setConfig(configuration);
session.connect();

I found the solution for this, I just added all those algorithms - KexAlgorithms diffie-hellman-group14-sha1 in the /etc/sshd_config and then restarted !

i just posted it here

http://77-thoughts.com/com-jcraft-jsch-jschexception-algorithm-negotiation-fail-at-com-jcraft-jsch-session-receive_kexinitunknown-source/

Changing some settings at destination server may not be possible every time. I faced this similar issue with "com.jcraft.jsch_0.1.27.jar" but after trying with latest version ie "jsch-0.1.54.jar" I have not faced this issue.

Also with this SFTP may open in interactive mode ie asking for username and pwd, for these case Enter key need to be pressed to continue. For this below is the solution:

config.put("PreferredAuthentications", "publickey,keyboard-interactive,password");
config.put("StrictHostKeyChecking", "no");
session.setConfig(config); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM