[英]Connect to a server with keyboard-interactive password authentication using jsch
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.但是当我尝试使用键盘交互密码连接到服务器时,我收到了
com.jcraft.jsch.JSchException: Auth fail
异常。
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.