java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
I'm connecting to a remote machine without keyboard-interactive authentication, using the above snippet.
But when I'm trying to connect to a server with keyboard-interactive password, I'm getting a com.jcraft.jsch.JSchException: Auth fail
exception.
I added these config and tested, yet didn't succed.
config.put("PreferredAuthentications", "password");
and
config.put("PreferredAuthentications",
"keyboard-interactive,password");
Try this.
JSch jSch;
try {
Properties properties = new Properties();
properties.put("PreferredAuthentications", "publickey,keyboard-interactive,password");
properties.put("StrictHostKeyChecking", "no");
properties.put("UseDNS", "no");
jSch = new JSch();
Session session = jSch.getSession("username", "host/ip", 22);
session.setConfig(properties);
session.setTimeout(10 * 1_000);
session.setPassword("password");
session.connect();
Channel channel = session.openChannel("shell");
channel.connect();
} catch (Exception e) {
e.printStackTrace();
} finally {
channel.disconnect();
session.disconnect();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.