当前位置:   article > 正文

java取消 验证,Java JSchException:身份验证取消

com.jcraft.jsch.jschexception: auth cancel

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.

Below is an extract from the logs

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

Code used to established connection

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);

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;

}

解决方案

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.

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.

For private key authentication with JSch see for example:

Can we use JSch for SSH key-based communication?

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号