我们正在使用该库通过 ssh 使用用户名和密码进行连接。有时,connection.authenticateWithPassword 方法返回 false(收到消息:SSH_MSG_USERAUTH_FAILURE),而其他方法可以正常返回 true。 用户名和密码在所有情况下都是正确的。
目前尝试连接的方法有很多:publickey、gssapi-keyex、gssapi-with-mic 和密码。其中存在password方法,实际上,connection.isAuthMethodAvailable(this.username, "password")方法返回true。
我们已经添加了库日志记录,但到目前为止我们还没有发现任何错误。
有什么想法可以帮助我们吗?
private Connection createConnection() throws IOException, InterruptedException {
logger.debug("Creating ssh connection...");
Connection connection = new Connection(this.ip, this.port);
connection.setTCPNoDelay(this.tcpNoDelay);
connection.connect(null, this.connectTimeout, this.kexTimeout);
if(connection.isAuthMethodAvailable(this.username, "password")) {
if(!connection.authenticateWithPassword(this.username, this.password)) {
logger.debug("Authentication failed!");
connection.close();
throw new IOException("Authentification failed");
}
} else {
logger.debug("Authentication password method is not available!!");
}
logger.debug("Connection was created successfull!");
return connection;
}
最佳答案
您能否提供有关成功和失败的更多详细信息。不清楚在单个设备上成功和失败是否是随机的,或者您成功地对一台设备进行了身份验证,但在另一台设备上却失败了?
如果针对特定设备始终失败,那么该设备会报告哪些身份验证选项?
关于Java SSH Ganymed - 尝试使用用户名和密码连接时出现随机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55690098/