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

文章讲述了在使用SSH2和SFTP协议通过ApacheMINASSHD服务建立连接时,如果长时间未操作,连接会因默认的超时设置(IDLE_TIMEOUT为10分钟,AUTH_TIMEOUT为2分钟)而断开。要修改这些超时时间,可以复制并修改`CoreModuleProperties`类中的相应参数,或者利用类加载机制来改变这个变量的值。
5322

被折叠的 条评论
为什么被折叠?



