You are here

Java SSH Client

SSHJ was used.
https://github.com/hierynomus/sshj

  1. SSHClient sshClient = new SSHClient();
  2.  
  3. //sshClient.loadKnownHosts();
  4. //disable HostKey verification
  5. sshClient.addHostKeyVerifier(new PromiscuousVerifier());
  6. sshClient.connect(getConfiguration().shcIpAddress());
  7. sshClient.authPassword(getConfiguration().shcAdminUserName(), getConfiguration().shcAdminPassword());
  8.  
  9. try {
  10. final Session session = sshClient.startSession();
  11. try {
  12. final Session.Command cmd = session.exec("echo -n > /var/log/logs.txt");
  13. System.out.println( IOUtils.readFully(cmd.getInputStream()).toString());
  14. cmd.join(5, TimeUnit.SECONDS);
  15. System.out.println("\n** clearLogs exit status: " + cmd.getExitStatus());
  16. } finally {
  17. session.close();
  18. }
  19. } finally {
  20. sshClient.disconnect();
  21. }

Ref: https://www.javacodegeeks.com/2015/08/commons-vfs-sshj-and-jsch-in-comparison.html
http://stackoverflow.com/questions/7873909/dealing-with-host-key-not-verifiable-could-not-verify-ssh-rsa-host-key-with
https://www.javacodegeeks.com/2015/08/commons-vfs-sshj-and-jsch-in-comparison.html
http://www.programcreek.com/java-api-examples/index.php?api=net.schmizz.sshj.SSHClient
https://github.com/sparsick/comparison-java-ssh-libs

Blog: