得到“授权取消".通过JSch使用密码进行身份验证时 [英] Getting "Auth cancel" when authenticating using password with JSch

查看:457
本文介绍了得到“授权取消".通过JSch使用密码进行身份验证时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Java执行Unix命令.我正在使用JSch库.

I'm trying to execute a Unix command from Java. I'm using the JSch library.

这是我的代码:

try{
    Session session = new JSch().getSession("*****", "****", 22);        
    session.setPassword("****");
    java.util.Properties config = new java.util.Properties(); 
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect();
    Channel channel=session.openChannel("exec");
    ((ChannelExec)channel).setCommand("pwd");
    InputStream in=channel.getInputStream();
    byte[] tmp=new byte[1024];
    while(in.available()>0){
          int i=in.read(tmp, 0, 1024);
          System.out.print(new String(tmp, 0, i));
    }
    channel.disconnect();
    session.disconnect();
}catch(Exception e){
    System.out.println(org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e));
} 

我一直收到身份验证取消"错误.我无法登录,因此无法执行任何操作.

I keep getting a "Auth Cancel" error. I am not able to login so that's before I can execute anything.

以下是请求的日志:

INFO: Connecting to ***** port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-6.3.8.79 SSH Tectia Server
INFO: Local version string: SSH-2.0-JSCH-0.1.42
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server->client aes128-ctr hmac-sha1 none
INFO: kex: client->server aes128-ctr hmac-sha1 none
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: ssh_rsa_verify: signature true
WARN: Permanently added '*****' (RSA) to the list of known hosts.
INFO: SSH_MSG_NEWKEYS sent
INFO: SSH_MSG_NEWKEYS received
INFO: SSH_MSG_SERVICE_REQUEST sent
INFO: SSH_MSG_SERVICE_ACCEPT received
INFO: Authentications that can continue: keyboard-interactive,password
INFO: Next authentication method: keyboard-interactive
INFO: Disconnecting from **** port 22
com.jcraft.jsch.JSchException: Auth cancel
    at com.jcraft.jsch.Session.connect(Session.java:451)
    at com.jcraft.jsch.Session.connect(Session.java:150)
    at unix.UnixConnect.main(UnixConnect.java:19)

我在做什么错了?

推荐答案

您已将键盘交互式身份验证设置为首选身份验证方法(默认设置).

You have a keyboard interactive authentication set as preferred authentication method (it's the default).

但是,您没有实现凭据提示. setPassword不能(也不能)用于键盘交互式身份验证.

Yet, you do not implement a prompt for credentials. The setPassword is not (and cannot) be used for the keyboard interactive authentication.

如果您实际上要使用密码验证,请使其成为首选:

If you actually want to use a password authentication, make it preferred:

config.put("PreferredAuthentications", "password");


不用说:如果您关心安全性,请不要使用StrictHostKeyChecking=no

这篇关于得到“授权取消".通过JSch使用密码进行身份验证时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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