当用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. iOS-动态调整UITableViewCell的高度

    OS-动态调整UITableViewCell的高度iOS开发文档, by 友盟翻译组 stefaliu. 大概你第一眼看来,动态调整高度是一件不容易的事情,而且打算解决它的第一个想法往往是不正确的.在 ...

  2. verilog 学习笔记

    1.在寄存器中: -1=1111 -2=1110 -3=1101 2.{1,0}=64‘H00000001_00000000;//默认是32位的位数-拼接: 3.defparam P1.Depth=1 ...

  3. Qt隐藏标题栏

    setWindowFlags (Qt::CustomizeWindowHint)setWindowFlags (Qt::FramelessWindowHint)两个函数都可以去掉标题栏,区别是第一个可 ...

  4. [shell基础]——split命令

    测试文本 # cat name1.txt name1 alvin1 name2 alvin2 name3 alvin3 name4 alvin4 此时目录下就只有这个文件 # ls name1.txt ...

  5. Machine Learning 学习笔记 (3) —— 泊松回归与Softmax回归

    本系列文章允许转载,转载请保留全文! [请先阅读][说明&总目录]http://www.cnblogs.com/tbcaaa8/p/4415055.html 1. 泊松回归 (Poisson ...

  6. python关于字典的使用方法

    #-*- coding:utf-8 -*-#Author:gxli#定义字典id_db={ 233333199211222342:{ 'name':'xiaoa', 'age':23, 'addr': ...

  7. Java程序员面试中的多线程问题

    很多核心Java面试题来源于多线程(Multi-Threading)和集合框架(Collections Framework),理解核心线程概念时,娴熟的实际经验是必需的.这篇文章收集了Java线程方面 ...

  8. oracle查看最大长度

    select s.ids from Student s where length(s.ids)=311 select max(length(s.ids)) from Student s

  9. 简单的C语言小学四则运算设计

    题目:设计一个简单的四则运算编辑器 思路:我使用的是C语言编程,看到题目首先要随机出3个随机数,其中两个为100以内的随机数(a,b),一个为0~3的随机数(k). k值的变化使得+ - * /的变化 ...

  10. xml基础学习笔记05

    Xpath快速解析 如题一样,本篇主要说说Xpath快速查找XML文档   * Xpatn.Xquery,是专门用来查询xml的语言   * 查询xml非常快   Xpatn.Xquery,是专门用来 ...