0

I'm developing java program to connect with windows server over ssh. For this I used jcraft on java. And the ssh server is copSSH. The implementation throws

Error: com.jcraft.jsch.JSchException: Algorithm negotiation fail

error on java. At the same time it shows

fatal: Unable to negotiate with 192.168.28.111: no matching cipher found. Their offer: aes128-cbc,3des-cbc,blowfish-cbc [preauth]

on CopSSH.

Java code block

public void sshExecPassword(String host, String USERNAME, String PASSWORD, String command) {
    App objApp = new App();
    int port = 22;
    try {
        /**
         * Create a new Jsch object This object will execute shell commands
         * or scripts on server
         */
        JSch jsch = new JSch();

        /*
         * Open a new session, with your username, host and port Set the
         * password and call connect. session.connect() opens a new
         * connection to remote SSH server. Once the connection is
         * established, you can initiate a new channel. this channel is
         * needed to connect to remotely execution program
         */
        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");

        Session session = jsch.getSession(USERNAME, host, port);
        session.setConfig(config);
        session.setPassword(PASSWORD);
        session.connect();

        // create the excution channel over the session
        ChannelExec channelExec = (ChannelExec) session.openChannel("exec");

        // Gets an InputStream for this channel. All data arriving in as
        // messages from the remote side can be read from this stream.
        InputStream in = channelExec.getInputStream();

        // Set the command that you want to execute
        // In our case its the remote shell script
        String str = command;
        channelExec.setCommand(str);
        channelExec.connect();

        // Read the output from the input stream we set above
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        // retrieve the exit status of the remote command corresponding to
        // this channel
        int exitStatus = channelExec.getExitStatus();

        // Safely disconnect channel and disconnect session. If not done
        // then it may cause resource leak
        channelExec.disconnect();
        session.disconnect();

        if (exitStatus < 0) {
            System.out.println("Done, but exit status not set! " + exitStatus);
            objApp.writeLogs("120","Done, but exit status not set! ");
        } else if (exitStatus > 0) {
            System.out.println("Done, but with error!");
            objApp.writeLogs("120","Done, but with error!");
        } else {
            System.out.println("Done!");
            objApp.writeLogs("121","SSH connection successful");
        }

    } catch (Exception e) {
        System.err.println("Error: " + e);
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        objApp.writeLogs("120", sw.getBuffer().toString());
    }
}

And the CopSSH host following versions

OpenSSH_7.1p2, OpenSSL 1.0.2e 3 Dec 2015

Can any one suggest a fix for it?

sugunan
  • 4,408
  • 6
  • 41
  • 66

2 Answers2

0

That happens due to lacking support for legacy ciphers in more recent releases of OpenSSH. Check this Copssh FAQ for a solution. Background information can also be found here.

itefix
  • 66
  • 4
  • 1
    Based on the domain/URL of your link(s) being the same as, or containing, your user name, you appear to have linked to your own site/a site you're affiliated with. If you do, you *must disclose that it's your site*. If you don't disclose affiliation, it's considered spam. See: [**What signifies "Good" self promotion?**](//meta.stackexchange.com/q/182212) and [the help center on self-promotion](//stackoverflow.com/help/promotion). Disclosure must be explicit, but doesn't need to be formal. When it's your own *personal* content, it can just be something like "on my site…", "on my blog…", etc. – Makyen Jun 25 '18 at 03:18
0

Latest jcraft jar fix the issue

sugunan
  • 4,408
  • 6
  • 41
  • 66