【问题标题】:Java SSH Ganymed - Random error to try to connect with username and passwordJava SSH Ganymed - 尝试使用用户名和密码连接时出现随机错误
【发布时间】:2019-04-15 13:18:29
【问题描述】:

我们正在使用该库通过用户名和密码通过 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


    【解决方案1】:

    您能否提供有关成功和失败的更多详细信息。不清楚是在单个设备上成功和失败是随机的,还是您成功对一台设备进行身份验证,但对另一台设备却失败了?

    如果针对特定设备始终失败,那么该设备会报告哪些身份验证选项?

    【讨论】:

    • 我们有两种不同的设备,但两者的行为都是随机的。有时一个设备响应成功,然后响应失败。连接打开,使用,然后关闭。始终关闭连接。我们是否必须在调用 connection.connect 和 connection.authenticateWithPassword 方法之间等待更多时间?还是您认为还有其他问题?
    • 您可能应该提高日志记录级别,以查看日志中是否有任何问题提示。如果随机尝试失败并且您确定密码正确,那么您应该检查服务器以了解原因。
    猜你喜欢
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    相关资源
    最近更新 更多