我目前看到这个问题,当试图SSH入使用JSch框。我已经使用Cygwin测试了连接,并且它可以无缝连接。我已经生成密钥对并将公钥放在远程服务器上的authorized_keys
文件中。Java JSchException:身份验证取消
下面是从日志中提取用于建立连接
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);
这里
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
代码是用户信息界面
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;
}
您可以编辑您的问题,包括您使用调用jsch,使这个连接的代码?如果您使用密钥文件,密钥文件的名称是什么? – Kenster
对不起,我对SSH相当陌生我相信我使用的密钥是id_rsa – joey7492
有点偏离主题,但仍然很重要:永远不要将任何密码字符串硬编码到生产二进制文件中。 – gustafbstrom