I am trying to use java to connect to a Linux server which has a two-step verification login. I'm using the jsch library, this is the code I've got so far:
session = jsch.getSession(username, ip);
Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword(password);
session.connect();
System.out.println("Connected to " + ip);
Obviously when I run this script I get an "Auth failed" error as I haven't enter the authentication key. So how do I login using the verification key. If this isn't possible could someone suggest a library that has this functionality.
This is logging into the server using putty. So you enter the username, then the time based generated code, then the password.
I worked this out eventually, you have to implement UserInfo and UIKeyboardInteractive. Use the promptKeyboardInteractive method, to make it return the authentication key, shown in the following code which works for me:
(PasswordUtils.verif_code() is the static method which generates the key)