Search code examples
sshnetwork-programmingserverjschpublic-key-exchange

SSH connection problems in JSch


I am trying to connect to a server using JSch. I get the "Negotiation fail" error. I checked the sshd_config file and got the following info:

UsePAM yes
PasswordAuthentication no
Ciphers aes128-ctr,aes256-ctr,arcfour256,arcfour,aes128-cbc,aes256-cbc
AllowTcpForwarding no
PermitRootLogin no

The rest of the scripts are commented out. As you see it doesn't mention anything about supported Key Exchange methods. 1. Does this seem to be the problem? or is there any other reason this error shows up? It is very hard for me to get the approval to make changes and test, so I wanted to make sure first and then apply the changes.

Also, this is all I get from the logger:

INFO: Connecting to xx.xxx.xxx.xxx port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_5.1
INFO: Local version string: SSH-2.0-JSCH-0.1.31
INFO: SSH_MSG_KEXINIT received
INFO: SSH_MSG_KEXINIT sent
Exception in thread "main" com.jcraft.jsch.JSchException: Algorithm negotiation fail
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:540)
    at com.jcraft.jsch.Session.connect(Session.java:288)
    at com.jcraft.jsch.Session.connect(Session.java:145)
    at SSHConnection.connect(SSHConnection.java:21)
    at SSHConnection.main(SSHConnection.java:25)
  1. Is there any other ways to find out the Key Exchange methods supported by the server?
  2. Are there other ways to connect to this server? I need to integrate this into my Java program.

Solution

  • I found the issue, it turns out that I had to download the Java Cryptography Extension (JCE) and replace the files with the ones that exist in the security folder in the following path: C:\Program Files\Java\jre6\lib\security\

    Hope this will help whoever has the same issue.