当前位置: 首页 > 工具软件 > Apache SSHD > 使用案例 >

Apache SSHD服务端:ssh2、sftp 登录验证超时时间、连接断开超时时间

燕烨
2023-12-01

通过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>
            <artifactId>sshd-core</artifactId>
            <version>2.8.0</version>
        </dependency>

代码

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> 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分钟

 类似资料: