Java JSchException:身份验证取消 [英] Java JSchException: Auth cancel

查看:162
本文介绍了Java JSchException:身份验证取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用JSch放入ssh到一个盒子时,我当前看到此问​​题.我已经使用Cygwin测试了连接,并且可以无缝连接.我已经生成了密钥对,并将公钥放置在远程服务器上的authorized_keys文件中.

I am currently seeing this issue when attempting to ssh into a box from using JSch. I have tested the connection using Cygwin and it connects seamlessly. I have generated the keypair and placed the Public key in authorized_keys file on the remote server.

下面是日志的摘录

INFO: Next authentication method: publickey
INFO: Authentications that can continue: keyboard-interactive,password
INFO: Next authentication method: keyboard-interactive
INFO: Authentications that can continue: password
INFO: Next authentication method: password
INFO: Disconnecting from xx.xx.xx.xx port 22
com.jcraft.jsch.JSchException: Auth cancel

用于建立连接的代码

Properties config = new Properties();
config.put("cipher",",aes256-cbc");
config.put("mac.c2s", "hmac-sha2-256");
config.put("KEXs", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
config.put("StrictHostKeyChecking", "no");
Session session = jsch.getSession(username,host,port);
session.setPassword(password);
session.setUserInfo(ui);
session.setConfig(config);
session.getPort();
session.connect();
session.setPortForwardingL(tunnelLocalPort,tunnelRemoteHost,tunnelRemotePort);

这是UserInfo ui的代码

Here is the code for the UserInfo ui

String password = null;

@Override
public String getPassphrase() {
    return null;
}
@Override
public String getPassword() {
    return password;
}
public void setPassword(String passwd) {
    password = passwd;
}

@Override
public boolean promptPassphrase(String message) {
    return false;
}
@Override
public boolean promptPassword(String message) {
    return false;
}
@Override
public boolean promptYesNo(String message) {
    return false;
}

推荐答案

当身份验证实现抛出JSchAuthCancelException时,将抛出身份验证取消".通常,当UserInfo实现从其方法之一返回false时,通常会发生这种情况.

The "Auth cancel" is thrown when the authentication implementation throws JSchAuthCancelException. What in turn usually happens when the UserInfo implementation return false from one of its methods.

您的代码未显示什么是ui.因此,在您向我们显示更多代码之前,我无法提供更多信息.

Your code does not show what is the ui. So I cannot provide more information until you show us more code.

您还撰写了有关密钥对的文章,但您的代码并未显示对密钥的任何使用.相反,您设置密码.

Also you write about key pair, yet your code does not show any use of a key. You instead set a password.

有关使用JSch进行私钥身份验证的示例,请参见:
我们可以使用JSch进行基于SSH密钥的通信吗?

For private key authentication with JSch see for example:
Can we use JSch for SSH key-based communication?

这篇关于Java JSchException:身份验证取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆