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?

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐