方法一:

用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

原文链接:http://www.cnblogs.com/aoyihuashao/p/3298950.html

SSH自动断开连接的原因、配置(转)的更多相关文章

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

    SSH自动断开连接的原因   方法一: 用putty/SecureCRT连续3分钟左右没有输入, 就自动断开, 然后必须重新登陆, 很麻烦. 在网上查了很多资料, 发现原因有多种, 环境变量TMOUT ...

  2. SSH自动断开连接的原因

    方法一: 用putty/SecureCRT连续3分钟左右没有输入, 就自动断开, 然后必须重新登陆, 很麻烦. 在网上查了很多资料, 发现原因有多种, 环境变量TMOUT引起,ClientAliveC ...

  3. Putty CentOS SSH 总是自动断开连接

    /********************************************************************** * Putty CentOS SSH 总是自动断开连接 ...

  4. WebSocket断开原因、心跳机制防止自动断开连接

    1.断开原因 WebSocket断开的原因有很多,最好在WebSocket断开时,将错误打印出来. ws.onclose = function (e) { console.log('websocket ...

  5. MySQL5.6数据库8小时内无请求自动断开连接

    问题: 最近的项目中,发现Mysql数据库在8个小时内,没有请求时,会自动断开连接,这是MySQL服务器的问题.The last packet successfully received from t ...

  6. SSH自动断开后重连的解决方案

    注:本文出自博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 本文源链接:https://www.cnblogs.com/chloneda/p/ssh-conn ...

  7. SSH自动断开处理

    解决ssh登录后闲置时间过长而断开连接 时我们通过终端连接服务器时,当鼠标和键盘长时间不操作,服务器就会自动断开连接,我们还的需要重新连接,感觉很麻烦,总结一下解决此问题的方法 方法一. 修改/etc ...

  8. MacOS下terminal防止ssh自动断开的方法和自动断开的原因

    之前换了个工作环境,用terminal连接远程服务器的时候老是出现自动断开的情况,搞得我很是郁闷.因为之前在家的时候,并没有出现过类似情况.后来在网上找了很久,发现国外网站上有个大神说应该是有些路由器 ...

  9. ssh一段时间无操作后自动断开连接(假死)问题

    平时使用ssh远程服务器的时候(注:远程虚拟机一般不会有这个问题),一段时间没有操作,ssh连接就会处于假死状态,以至于需要重新进行ssh连接,不管你用的什么远程工具都会出现这个问题,那么通过心跳检测 ...

随机推荐

  1. 安装Oracle服务端后配置注册表与PL/SQL

    1.流程: 1.安装Oracle客户端(绿色版和安装版均可,建议安装在和Oracle服务端文件夹并行的路径下,例:E:\app\yginuo\product\11.2.0) 2.配置环境变量和注册表( ...

  2. Android实现屏蔽微信拉黑和删除联系人功能

    实现效果: 让微信永远弹不出那个删除的对话框不就相当于屏蔽掉该功能了吗?哈哈效果如图: 实现原理: 同样是利用AccessibilityService辅助服务,关于这个服务类还不了解的同学可以先看下我 ...

  3. 全球分布式数据库:Google Spanner(论文翻译)

    本文由厦门大学计算机系教师林子雨翻译,翻译质量很高,本人只对极少数翻译得不太恰当的地方进行了修改. [摘要]:Spanner 是谷歌公司研发的.可扩展的.多版本.全球分布式.同步复制数据库.它是第一个 ...

  4. MVC - 云服务器部署

    本章将和大家分享的是如果在云服务器上部署mvc,云服务器部署其实也不高大上,就和咋们在自己电脑上用iis发布部署站点一样,只是需要使用云解析把自己购买的域名解析到对应的自己的云服务器上,这些都是用的云 ...

  5. 设置npm安装模块目录<nodejs>

    nodejs安装模块命令: npm install <input_name> # 本地安装 npm install <input_name> -g # 全局安装 1.npm i ...

  6. My97DatePicker.js 之无效日期设置

    1.下载并引用My97DatePicker.js 2.将工作日休假的和周末上班的维护到数据库中 3.取出某段时间内的不上班日期集合 /// <summary> ///获取 无效日期集合 1 ...

  7. Java 重写hashCode 方法和equals方法

    package Container; import java.util.HashSet; import java.util.Iterator; /* Set 元素是无序的(存入和取出的顺序不一定一致) ...

  8. 谈 jquery中.band() .live() .delegate() .on()的区别

    bind(type,[data],fn) 为每个匹配元素的特定事件绑定事件处理函数 $("a").bind("click",function(){alert(& ...

  9. 转:frame和iframe的区别

    1.frame不能脱离frameSet单独使用,iframe可以: 2.frame不能放在body中:如下可以正常显示: <!--<body>--> <frameset ...

  10. Hibernate框架Criteria查询

    本文章适合一些初学者 一.使用Criteria查询数据        1.条件查询            1.1:使用Criteria查询的步骤                    1.使用Sess ...