Java ssh client

2019-06-04 01:25发布

问题:

I'm trying to create a web app which will check several service status, server stats etc. I found this http://www.jcraft.com/jsch/ seems to be pretty nice ssh java implementation. But every time I log in in to server I'm prompted to confirm RSA key fingerprint like this :

How can I override this, to always confirm yes without any prompts? I want to remove the whole swing part, I want to make this without any interaction, like this example code I took from the examples available on jscraft.com :

http://www.jcraft.com/jsch/examples/Exec.java

I'm not so familiar with swing and with java in general.

回答1:

   public class ManoUserInfo implements UserInfo {

String passwd;

public void setPassword(String pass) {
    passwd = pass;
}

@Override
public String getPassphrase() {
    return null;
}

public String getPassword() {
    return passwd;
}

public boolean promptPassword(String arg0) {
    return true;

}

public boolean promptPassphrase(String arg0) {
    return true;
}
//this method responsible for that message, so just make it return true
public boolean promptYesNo(String arg0) {
  //  Object[] options = {"yes", "no"};
  /*  int foo = JOptionPane.showOptionDialog(null,
            arg0,
            "Warning",
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.WARNING_MESSAGE,
            null, options, options[0]);*/
    return true;
}

public void showMessage(String message) {
    JOptionPane.showMessageDialog(null, message);
}


回答2:

You have to understand why this message pops up.

SSH is a secure service, meaning that the identity of the client and the identity of the server are guaranteed. To guarantee that you actually reached the server you want to reach (for how it is possible that you connect to the wrong server without your knowledge, google "DNS cache poisoning"), the client displays the recieved server name and fingerprint. These values identify the server. You are supposed to look if this is in fact the fingerprint you generated on the server by comparing the fingerprint through a secure channel (via telephone with the server admin, for instance).

Having said that, usual SSH clients save your decision to accept the fingerprint/server name and do not ask again. It seems that your client does not. So you either have the option to change the source code (if it's licensed under an open license) or find a way to automatically press "Yes" whenever this question pops up (this can be achieved with toolkits like Autoit 3 with a very short script).



回答3:

check out http://sourceforge.net/projects/sshtools/



标签: java swing ssh