简体   繁体   English

使用 jsch 通过键盘交互式密码认证连接到服务器

[英]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.

相关问题 使用JSch无需用户名或密码即可连接到服务器 - Connect to server without username or password using JSch 使用JSch SFTP客户端连接到FileZilla服务器时出错 - Error to connect to FileZilla server using JSch SFTP client Java SWT使用Jcraft JSch连接到远程服务器 - java SWT to connect to remote server using Jcraft JSch 使用 jsch 连接到托管在 azure 中的 sftp 服务器时连接重置 - Connection reset when using jsch to connect to an sftp server hosted in azure SSH 中使用 jcraft JSch 的 Java 密码身份验证失败并显示“身份验证失败”,但命令行“ssh”有效 - SSH password authentication in Java using jcraft JSch fails with "Auth fail" but command-line "ssh" works 无法使用 JSch 连接到服务器端口 23 - Cannot connect to server port 23 with JSch 我们如何使用公共密钥通过服务器托管的应用程序使用JSch连接到SFTP服务器 - How can we use public key to connect to a SFTP server using JSch from an application hosted in server 在远程服务器 (JSch) 上打开应用程序时显示交互式服务检测 - Interactive Services Detection showing when opening an application on remote server (JSch) scp 使用 Jsch 复制文件要求密码 - scp using Jsch to copy file asking for password 使用具有公钥/私钥认证的JSch从远程SFTP服务器接收数据。 任何例子? - Ingesting data from remote SFTP server using JSch with public/private key authentication. Any examples?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM