当用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. PHY

    Linux 下smi/mdio总线通信 韩大卫@吉林师范大学 下面代码描述了在用户层访问smi/mdio总线, 读写phy芯片寄存器的通用代码.Linux内核2.6以上通用. 将下面代码编译后,将可执 ...

  2. OC开发中运用到的枚举

      一  常见枚举的定义: typedef enum { LOGIN_SUCCESS, USER_NAME, USER_PASSWORD, OLD_LAT, OLD_LNG }FIELD_SAVED; ...

  3. Why does uitableview cell remain highlighted?

    What would cause a tableview cell to remain highlighted after being touched? I click the cell and ca ...

  4. git简单入门

    git简单入门 标签(空格分隔): git git是作为程序员必备的技能.在这里就不去介绍版本控制和git产生的历史了. 首先看看常用的git命令: git init git add git comm ...

  5. css3 forwards、backwards、both

    animation-fill-mode 属性规定动画在播放之前或之后,其动画效果是否可见. none 不改变默认行为. forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义). ...

  6. Java应用的优秀管理工具Maven的下载安装及配置

    1.进入Maven的官方下载地址:http://maven.apache.org/download.cgi 2.向下滚动页面,点击这个zip包进行下载: 3.将压缩包解压后剪切到Mac的某个目录下就完 ...

  7. mysql存储过程和游标以及if-else,while典型实例

    -- -------------------------------------------------------------------------------- -- Routine DDL - ...

  8. android 通过AlarmManager实现守护进程

    场景:在app崩溃或手动退出或静默安装后能够自动重启应用activity 前提:得到系统签名 platform.pk8.platform.x509.pem及signapk.jar 三个文件缺一不可(系 ...

  9. jQuery(Keep for myself)

    jQuery API : http://www.w3cschool.cc/manual/jquery/ 1. jQuery是一个JavaScript函数库. jQuery是一个轻量级的"写的 ...

  10. Leetcode#145 Binary Tree Postorder Traversal

    原题地址 递归写法谁都会,看看非递归写法. 对于二叉树的前序和中序遍历的非递归写法都很简单,只需要一个最普通的栈即可实现,唯独后续遍历有点麻烦,如果不借助额外变量没法记住究竟遍历了几个儿子.所以,最直 ...