当前位置: 代码迷 >> 综合 >> How to solve the problem that the cursor does not respond after ssh connection for a period of time
  详细解决方案

How to solve the problem that the cursor does not respond after ssh connection for a period of time

热度:79   发布时间:2023-12-15 00:36:47.0

通常情况下,通过ssh连接openssh-server的时候,过几分钟就会出现没有响应的情况,对于这一现象,可以通过如下两种途径解决。

1.修改配置文件

1.1. server端配置

修改server端的 etc/ssh/sshd_config

ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后client响应,从而保持连接
ClientAliveCountMax 3 #server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应

1.2. 客户端配置

修改client端的 etc/ssh/ssh_config 添加以下:(在没有权限改server配置的情形下)

ServerAliveInterval 60 #client每隔60秒发送一次请求给server,然后server响应,从而保持连接
ServerAliveCountMax 3  #client发出请求后,服务器端没有响应得次数达到3,就自动断开连接,正常情况下,server不会不响应

2. 命令行加参数

在命令参数里

ssh -o ServerAliveInterval=60  user@hostname 

这样只会在需要的连接中保持持久连接, 毕竟不是所有连接都要保持持久的

修改完成重启ssh服务即可。

参考文献:

  • ssh 远程连接自动断开解决
  相关解决方案