通过ssh2、sftp协议连接基于Apache MINA SSHD的服务时,长时间不用连接会自动断开我们来看一下默认断开时间和如何修改断开时间。

超时报错日志

Disconnecting(ServerSessionImpl[{username}@/{ip}:{port}]): SSH2_DISCONNECT_PROTOCOL_ERROR - Detected IdleTimeout after 600028/600000 ms

依赖版本

        <dependency>
            <groupId>org.apache.sshd</groupId>
            &lt;artifactId&gt;sshd-core</artifactId&gt;
            <version&gt;2.8.0</version&gt;
        </dependency&gt;

代码

org.apache.sshd.core.CoreModuleProperties的IDLE_TIMEOUT

AUTH_TIMEOUT是顺便发现参数

    /**
     * Key used to retrieve the value of the timeout after which it will close the connection if the other side has not
     * been authenticated - in milliseconds.
     */
    public static final Property<Duration&gt; AUTH_TIMEOUT
            = Property.duration("auth-timeout", Duration.ofMinutes(2));
    /**
     * Key used to retrieve the value of idle timeout after which it will close the connection - in milliseconds.
     */
    public static final Property<Duration> IDLE_TIMEOUT
            = Property.duration("idle-timeout", Duration.ofMinutes(10));

调整方式

没有提供外部配置可以通过将此类复制项目代码中修改时间,启动时会先加载自定义的此类。
可以提供其他影响加载的方式修改此变量

结论

追踪代码流程不说了,登录验证超时时间2分钟,连接空闲断开的默认超时时间10分钟

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注