Algorithm negotiation fail SSH in Jenkins

TL;DR edit your sshd_config and enable support for diffie-hellman-group-exchange-sha1 and diffie-hellman-group1-sha1 in KexAlgorithms: KexAlgorithms [email protected],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 I suspect that the problem appeared after the following change in OpenSSH 6.7: “The default set of ciphers and MACs has been altered to remove unsafe algorithms.”. (see changelog). This version was released on Oct, 6, and made it on … Read more

Sending commands to server via JSch shell channel

Try this: JSch jsch = new JSch(); try { Session session = jsch.getSession(“root”, “192.168.0.1”, 22); java.util.Properties config = new java.util.Properties(); config.put(“StrictHostKeyChecking”, “no”); session.setConfig(config); session.connect(); String command = “lsof -i :80”; Channel channel = session.openChannel(“exec”); ((ChannelExec) channel).setCommand(command); channel.setInputStream(null); ((ChannelExec) channel).setErrStream(System.err); InputStream in = channel.getInputStream(); channel.connect(); byte[] tmp = new byte[1024]; while (true) { while (in.available() > … Read more

Simple SSH connect with JSch

You have to execute that code in another thread so you don’t hang the UI thread is what that exception means. If the UI thread is executing a network call it can’t repaint the UI so your users sees a frozen UI that doesn’t respond to them while the app is waiting on the network … Read more

Multiple commands through JSch shell

The command is a String and can be anything the remote shell accepts. Try cmd1 ; cmd2 ; cmd3 to run several commands in sequence. Or cmd1 && cmd2 && cmd3 to run commands until one fails. Even this might work: cmd1 cmd2 cmd3 or in Java: channel.setCommand(“cmd1\ncmd2\ncmd3”); Sidenote: Don’t put passwords and user names … Read more

How do I run SSH commands on remote system using Java? [closed]

Have a look at Runtime.exec() Javadoc Process p = Runtime.getRuntime().exec(“ssh myhost”); PrintStream out = new PrintStream(p.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); out.println(“ls -l /home/me”); while (in.ready()) { String s = in.readLine(); System.out.println(s); } out.println(“exit”); p.waitFor();