SSH自动断开连接的原因-20200323

方法一:

用putty/SecureCRT连续3分钟左右没有输入, 就自动断开, 然后必须重新登陆, 很麻烦.

在网上查了很多资料, 发现原因有多种, 环境变量TMOUT引起,ClientAliveCountMax和ClientAliveInterval设置问题或者甚至是防火墙的设置问题. 所以可以这么尝试:

1, echo $TMOUT
如果显示空白,表示没有设置, 等于使用默认值0, 一般情况下应该是不超时. 如果大于0, 可以在如/etc/profile之类文件中设置它为0.
Definition: TMOUT: If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if input does not arrive.
2. ClientAliveInterval 60
在/etc/ssh/sshd_config中增加ClientAliveInterval 60, ClientAliveInterval指定了服务器端向客户端请求消息的时间间隔, 默认是0, 不发送.而ClientAliveInterval 60表示每分钟发送一次, 然后客户端响应, 这样就保持长连接了.这里比较怪的地方是:不是客户端主动发起保持连接的请求(如FTerm, CTerm等),而是需要服务器先主动.

另外,至于ClientAliveCountMax, 使用默认值3即可.ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值, 就自动断开. 正常情况下, 客户端不会不响应.

ClientAliveCountMax
Sets the number of client alive messages (see below) which may be
sent without sshd(8) receiving any messages back from the client.
If this threshold is reached while client alive messages are
being sent, sshd will disconnect the client, terminating the ses-
sion. It is important to note that the use of client alive mes-
sages is very different from TCPKeepAlive (below). The client
alive messages are sent through the encrypted channel and there-
fore will not be spoofable. The TCP keepalive option enabled by
TCPKeepAlive is spoofable. The client alive mechanism is valu-
able when the client or server depend on knowing when a connec-
tion has become inactive.

The default value is 3. If ClientAliveInterval (see below) is
set to 15, and ClientAliveCountMax is left at the default, unre-
sponsive SSH clients will be disconnected after approximately 45
seconds. This option applies to protocol version 2 only.

ClientAliveInterval
Sets a timeout interval in seconds after which if no data has
been received from the client, sshd(8) will send a message
through the encrypted channel to request a response from the
client. The default is 0, indicating that these messages will
not be sent to the client. This option applies to protocol ver-
sion 2 only.
3. 启用putty keepalive
putty -> Connection -> Seconds between keepalives ( 0 to turn off ), 默认为0, 改为60
 
方法二:
 
  SSH的英文全称是Secure Shell。通过使用SSH,你可以把所有传输的数据进行加密,这样“中间人”这种攻击方式就不可能实现了, 而且也能够防止DNS和IP欺骗。还有一个额外的好处就是传输的数据是经过压缩的,所以可以加快传输的速度。 SSH有很多功能,它既可以代替telnet,又可以为ftp、pop、甚至ppp提供一个安全的“通道”。
    所谓 “中间人”的攻击方式,就是“中间人”冒充真正的服务器接收你的传给服务器的数据,然后再冒充你把数据传给真正的服务器。服务器和你之间的数据传送被“中间人”一转手做了手脚之后,就会出现很严重的问题。
中国E动网(www.edong.com)凭借优质的服务经验和精湛的专业技术受到了很多企业应用客户的青睐。IDC部特提出两种解决SSH超时断连解决方法供大家参考:
1、 配置服务器

#vi /etc/ssh/sshd_config

1)找到 ClientAliveInterval参数,如果没有就自己加一行

数值是秒,比如你设置为120 ,则是2分钟
ClientAliveInterval 120

2)ClientAliveCountMax
指如果发现客户端没有相应,则判断一次超时,这个参数设置允许超时的次数。如3 、5等自定义。

修改两项参数后如下:

ClientAliveInterval 120
ClientAliveCountMax 0   ###在不允许超时次数
重新加载sshd服务。退出客户端,再次登陆即可验证。

2、 配置客户端

#vi /etc/ssh/ssh_config

然后找到里面的
ServerAliveInterval

参数,如果没有,你同样自己加一个就好了,参数意义相同,都是秒数,比如5分钟等。

ServerAliveInterval 300

分类: 【1】Linux/shell

原文地址:https://www.cnblogs.com/xuanbjut/p/12550781.html

时间: 2024-08-12 06:25:35

SSH自动断开连接的原因-20200323的相关文章

SSH自动断开连接的原因

方法一: 用putty/SecureCRT连续3分钟左右没有输入, 就自动断开, 然后必须重新登陆, 很麻烦. 在网上查了很多资料, 发现原因有多种, 环境变量TMOUT引起,ClientAliveCountMax和ClientAliveInterval设置问题或者甚至是防火墙的设置问题. 所以可以这么尝试: 1, echo $TMOUT如果显示空白,表示没有设置, 等于使用默认值0, 一般情况下应该是不超时. 如果大于0, 可以在如/etc/profile之类文件中设置它为0.Definiti

Linux的SSH登录超时自动断开连接设置

关于ssh登录超时断开连接的设置有两个方面可以设置 1.修改sshd服务的配置文件sshd_config的内容 #ClientAliveInterval 0   指定了服务器向客户端请求消息的时间间隔 #ClientAliveCountMax 3   连接用户最大值 2.ssh -o ConnectTimeout=Time IP ssh -o ConnectTimeout=3 192.168.0.10 3.修改环境变量配置文件(.bash_profile /etc/bash_profile /e

Putty CentOS SSH 总是自动断开连接

/********************************************************************** * Putty CentOS SSH 总是自动断开连接 * 说明: * VPS中采用CentOS系统,SSH在使用过程中总是自动断开连接,太麻烦了, * 记得在Ubuntu中是没有这个问题的. * * 2018-7-9 深圳 宝安西乡 曾剑锋 ********************************************************

SSH自动断开处理

解决ssh登录后闲置时间过长而断开连接 时我们通过终端连接服务器时,当鼠标和键盘长时间不操作,服务器就会自动断开连接,我们还的需要重新连接,感觉很麻烦,总结一下解决此问题的方法 方法一. 修改/etc/ssh/sshd_config配置文件,找到ClientAliveCountMax(单位为分钟)修改你想要的值, 执行service sshd reload 方法二. 找到所在用户的.ssh目录,如root用户该目录在: /root/.ssh/ 在该目录创建config文件 vi /root/.s

客户端连接腾讯云服务总是自动断开连接解决办法

1.找到sshd_config配置文件 输入以下命令: vim /etc/ssh/sshd_config 在此文件中找到以下配置项: #ClientAliveInterval 0 #ClientAliveCountMax 3 去掉注释,改成 ClientAliveInterval 30 ClientAliveCountMax 86400 这两行的意思分别是 1.服务端每隔多少秒向客户端发送一个心跳数据 2.客户端多少次没有相应,服务器自动断掉连接 2.重启sshd服务 输入以下命令重启ssh配置

Oracle或PL/SQL自动断开连接解决参考

ORACLE自动断开数据库连接解决办法 方法一.直接修改资源配置文件 分三个步骤在sqlplus环境下完成. 第一步,查询资源文件,找到CONNECT_TIME所在的profile名. select resource_name,profile from dba_profiles; 第二步,用alter命令修改profile中的值: alter profile MONITORING_PROFILE limit connect_time unlimited;(或跟一个时间值,如1000,单位为分钟)

unity客户端自动断开连接

问题描述: 当unity失去焦点一段时间后,与photon服务器端断开连接 问题根源: 默认unity失去焦点后会暂停运行,导致连接超时,服务器端超时断开连接 解决方案: 连接服务器后,填加一句代码让unity在失去焦点的情况下继续执行游戏 Application.runInBackground = true; 原文地址:https://www.cnblogs.com/fzxiaoyi/p/8449684.html

ssh 自动输入密码连接

公司的linux服务器和交换机都是用户名和密码ssh连接的,每次连接时都要手动输入密码感觉很是麻烦 如果连接时不用输入密码就方便很多了,于是网上查了下说是有三种解决方法 1. 生成ssh公钥,建立和对方机器的信任关系: 2. 使用expect脚本: 3. 使用sshpass. 个人比较喜欢使用sshpass,配上 shell脚本后效率提高很多 sshpass 安装 (centos) yum install sshpass 基本用法:sshpass -p [密码] ssh [user]@[host

SSH 超时断开连接解决办法

配置服务器端: vi /etc/ssh/sshd.conf ClientAliveInterval 120 #以秒为单位 ClientAliveCountMax 0 #发现客户端没有相应,则判断一次超时,这个参数设置允许超时的次数 #重新加载sshd服务.退出客户端,再次登陆即可验证.