当用SSH Secure Shell连接Linux时,如果几分钟没有任何操作,连接就会断开,必须重新登陆才行,每次都重复相同的操作,很是烦人,本文总结了两种解决的方法。

方法1:更改ssh服务器的配置文件/etc/ssh/sshd_config

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() 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 messages is very different from TCPKeepAlive (below).
The client alive messages are sent through the encrypted channel and therefore will not be spoofable.
The TCP keepalive option enabled by TCPKeepAlive is spoofable.
The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.The default value is .
If ClientAliveInterval (see below) is set to , and ClientAliveCountMax is left at the default,
unresponsive SSH clients will be disconnected after approximately seconds.
This option applies to protocol version only. ClientAliveInterval Sets a timeout interval in seconds after which if no data has been received from the client,
sshd() will send a message through the encrypted channel to request a response from the client.
The default is , indicating that these messages will not be sent to the client. This option applies to protocol version only.

vim /etc/ssh/sshd_config

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

ClientAliveInterval 参数的数值是秒,比如你设置为540,就是9分钟.

ClientAliveInterval 540

对于ClientAliveCountMax

指如果发现客户端没有相应,则判断一次超时,这个参数设置允许超时的次数,比如10。

ClientAliveInterval 540

ClientAliveCountMax 10;

则代表允许超时 5400秒 = 90分钟。

方法2:配置客户端

1. linux下的ssh命令

vim /etc/ssh/ssh_config

然后找到里面的ServerAliveInterval 参数,如果没有你同样自己加一个就好了。参数意义相同,都是秒数,比如9分钟:

ServerAliveInterval 540

2. SecureCRT

设置反空闲,如下图所示

3 Putty

启用putty keepalive

putty -> Connection -> Seconds between keepalives ( 0 to turn off ),默认为0,改为60。

ssh超时断开的解决方法的更多相关文章

  1. 解决:Linux SSH Secure Shell(ssh) 超时断开的解决方法

    转载:http://www.cnblogs.com/jifeng/archive/2011/06/25/2090118.html 修改/etc/ssh/sshd_config文件,找到 ClientA ...

  2. linux ssh 经常断开 的解决方法

    1.现象 在linux ,用ssh进行远程连接时,经常会发生长时间后断线,或者是无响应,就像卡住的感觉(键盘输入不进去). 2.解决方法 在ssh客户端的linux设置 # sudo vim /etc ...

  3. SSH 超时断开连接解决办法

    配置服务器端: vi /etc/ssh/sshd.conf ClientAliveInterval 120 #以秒为单位(可以改大些) ClientAliveCountMax 0 #发现客户端没有相应 ...

  4. SSH连接自动断开的解决方法(deb/rpm)

    ######### 修改后的: ## # tail -f -n 20 sshd_config#MaxStartups 10:30:60#Banner /etc/issue.net # Allow cl ...

  5. secureCRT自动断开的解决方法

    转: secureCRT自动断开的解决方法 secureCRT自动断开的解决方法 在secureCRT上登录时,一段时间不用的话会自动断开,必须重新连接,有点麻烦. 有时候服务器端的 /etc/pro ...

  6. 因修改/etc/ssh权限导致的ssh不能连接异常解决方法

    因修改/etc/ssh权限导致的ssh不能连接异常解决方法 现象: $ssh XXX@192.168.5.21 出现以下问题 Read from socket failed: Connection r ...

  7. CentOS6.5 ssh远程连接缓慢解决方法

    UseDNS no GSSAPIAuthentication no 1.适用命令及方案如下:[远程连接及执行命令]ssh -p22 root@10.0.0.19ssh -p22 root@10.0.0 ...

  8. SSH连接LINUX乱码解决方法

    1.vi /etc/sysconfig/i18n 将内容改为 LANG="zh_CN.GB18030" LANGUAGE="zh_CN.GB18030:zh_CN.GB2 ...

  9. 【转】bash: ssh: command not found解决方法(linux)

    原文转自:http://www.cnblogs.com/ahauzyy/archive/2013/04/25/3043699.html 今天在搭建hadoop的开发环境中,用的是centsos6.0的 ...

随机推荐

  1. SoapUI-x64(app:url请求参数)

    SoapUI-x64-5.2.0_576025

  2. 在51系列中data,idata,xdata,pdata的区别

    在51系列中data,idata,xdata,pdata的区别: data:固定指前面0x00-0x7f的128个RAM,可以用acc直接读写的,速度最快,生成的代码 也最小. idata:固定指前面 ...

  3. C Primer Plus学习笔记

    1.汇编语言是特地的Cpu设计所采用的一组内部指令的助记符,不同的Cpu类型使用不同的Cpu C给予你更多的自由,也让你承担更多的风险 自由的代价是永远的警惕 2.目标代码文件.可执行文件和库 3.可 ...

  4. Z_blog博客尝试 http://www.uuxin.com/

    原来的博客由于没有备份所有数据全部丢失,很是郁闷. 又用Z-BLOG新建了一个博客.http://www.uuxin.com

  5. 软件工程随堂小作业——寻找“水桶”(C++)

    一.设计思想 思路与寻找一个水王相似,这次只是计数器和嫌疑人变量都设置为数组.每次选取一个ID与三个嫌疑人比较,若有相同则计数:若三个都不相同,则三个计数器都减一.若减为0,则从新赋值给嫌疑人. 二. ...

  6. 软件工程随堂小作业——随机四则运算Ⅱ(C++)

    一.设计思路 设计思路已给出,此处不再赘述. 二.源代码 (1)四则运算2.cpp(源文件) // 四则运算2.cpp : Defines the entry point for the consol ...

  7. Eigen库实现简单的旋转、平移操作

    本来课程要求用GUI界面来实现Eigen的旋转.平移操作的,但是接触GUI编程时间太短,虽然要求很简单,但是做了几天还是没有完成.就把命令行下面的简单的贴一下吧. main.cpp #include ...

  8. 国内最快的jquery cdn

    cdnjs.cn是cdnjs.com在国内的镜像服务,项目托管与著名的又拍云存储,目前又拍云在全国有几十个cdn节点,并且还在增加中. cdnjs.cn 托管的jquery相信会成为国内最快的jque ...

  9. 【反射】——Autofac 类型注册

    Autofac是.net界一款轻量化的IOC组件,使用Autofac可以帮助完成代码中很多依赖注入工作.在以前文章中,介绍过Autofac的配置过程(http://www.cnblogs.com/Jn ...

  10. mongo的insert和save比较

    insert仅仅是插入文档到集合中,如果记录不存在则插入,如果记录存在则忽略 save是在文档不存在时插入,存在时则是更新 下面代码不是为了演示insert和save的: foreach ($mens ...