There are other similar questions to this, but I don't feel like it answers mine. From a Java servlet I need to be able to ssh to any server on my company's network and dynamically handle this unknown key exception and then issue a command to get and display the current status of the server.
I saw one suggestion to use JSch session.setFingerprint, but it must have changed or something because far as I can tell, it doesn't exist. I'm using Netbeans.
Here's my code:
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String url = "validurl";
String user = "validuser";
String password = "validpassword";
printer.println ("HelloWorld!");
JSch ssh = new JSch();
ChannelShell ch = null;
Session session = null;
try {
session = ssh.getSession(user, "serverIP", 22);
session.setPassword(password);
session.connect();
ch = (ChannelShell)session.openChannel("shell");
ch.connect();
}
catch (JSchException e) {
System.out.println ("Exception: " + e);
}
catch (Exception e) {
System.out.println ("Exception: " + e);
}
Thanks! Devin