I'm trying to write a java program that will connect via ssh and do some stuff on a server at work (redhat linux). My box is windows. I read about sshj and I'm trying to get the example to work. I've worked through most of the dependencies and now I have an error dealing with public/private keys and unfortunately I don't know much there either (yes, it's a perfect storm of newbie-ness!). Here's the error:
Exception in thread "main" net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Could not verify ssh-rsa
host key with fingerprint 5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3d
for myserver
on port 22
Here's 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;
/** This examples demonstrates how a remote command can be executed. */
public class sshBuddy {
public static void main(String... args)
throws IOException {
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
//ssh.addHostKeyVerifier("5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3d");
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!