1

I want to automate connect to a ssh server with keyboard-interactive authentication(or challenge-response authentication) using jsch. I'd already set userinfo and config like this.

session.setUserInfo(myUserInfo);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("PreferredAuthentications",
                    "publickey,keyboard-interactive,password");

myUserInfo object implement the UserInfo interface When I debug the source, I'm always getting a com.jcraft.jsch.JSchException: Auth fail exception. Somebody said myUserInfo should implement UIKeyboardInteractive. But I can't understand the official JSch UserAuthKI example. It's too complicated to understand. I just want get a connection automate. Who can give me a simple example, please. Thanks.

Devin
  • 21
  • 2

1 Answers1

0

I found solution. Let's myUserInfo class implements UIKeyboardInteractive interface. And rewrited promptKeyboardInteractive method like this.

@Override
public String[] promptKeyboardInteractive(String destination, String name,
                                              String instruction, String[] prompt,
                                              boolean[] echo)
{
       System.out.println("#####promptKeyboardInteractive#####");
       System.out.println("destination: " + destination);
       System.out.println("name: " + name);
       System.out.println("instruction: " + instruction);
       System.out.println("prompt.length: " + prompt.length);
       System.out.println("prompt[0]: " + prompt[0]);
       System.out.println("echo[0]: " + echo[0]);
       String[] response=new String[prompt.length];
       response[0] = passwd;
       return response;
}

It's works. I can get a connection from the ssh server.

Devin
  • 21
  • 2