I am trying to write a java program that will connect via ssh and do some things on the server at work (redhat linux). My box is the windows. I read about sshj and I am trying to get this example to work. I worked on most of the dependencies, and now I have a bug related to public / private keys, and, unfortunately, I don't know much either (yes, this is a perfect newbie storm!). Here's the error:
Exception in thread "main" net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Failed to verify ssh-rsahost key with fingerprint 5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3dfor myserveron port 22
Here is the code:
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class sshBuddy {
public static void main(String... args)
throws IOException {
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("myserver");
try {
ssh.authPublickey(System.getProperty("myusername"));
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("ping -c 1 google.com");
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
}
}
Any help would be appreciated, thanks!