目前大多数ssh服务是运行在Linux系统上的sshd服务。当访问终端在windows上时,各终端软件,如,putty,SecureCRT等,大多支持设置向服务器端自动发送消息,来防止终端定期超时。其实,服务器端也支持类似的设置,从服务器的角度防止链接超时。并且,当终端在Ubuntu
等Linux系统上时,客户端也可进行类似设置。
下面我们就介绍三种防止超时被踢出的方法,后两种情况的设置方法以及通过设置shell变量来达到此目的的方法:


1、 配置服务器



#vi /etc/ssh/sshd_config



1)找到 ClientAliveInterval参数,如果没有就自己加一行
数值是秒,比如你设置为120 ,则是2分钟

ClientAliveInterval 120



2)ClientAliveCountMax

指如果发现客户端没有响应,则判断一次超时,这个参数设置允许超时的次数。如3 、5等自定义
 
修改两项参数后如下:
----------------------------

ClientAliveInterval 120

ClientAliveCountMax 3   ### 0 不允许超时次数
 
修改/etc/ssh/sshd_config文件,将 ClientAliveInterval
0和ClientAliveCountMax
3的注释符号去掉,将ClientAliveInterval对应的0改成60,没有就自己输入。
ClientAliveInterval指定了服务器端向客户端请求消息 的时间间隔, 默认是0,
不发送.而ClientAliveInterval 60表示每分钟发送一次, 然后客户端响应,
这样就保持长连接了.ClientAliveCountMax,
使用默认值3即可.ClientAliveCountMax表示服务器发出请求后客户端没有响应的次数达到一定值, 就自动断开.
正常情况下, 客户端不会不响应.

重新加载sshd服务。退出客户端,再次登陆即可验证。
 
3)重启sshd
service
sudo
/etc/init.d/ssh restart




2、 配置客户端


#vi 
/etc/ssh/ssh_config
然后找到里面的

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



ServerAliveInterval 300

下面是man
sshd_config获取的描述信息

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 0, indicating that these messages will not be

            
sent to the client.  This option applies to
protocol version 2

            
only.

ClientAliveCountMax

Sets the number of client alive messages (see above) which
may

            
be sent without sshd receiving any messages back from the

            
client.  If this threshold is reached while client
alive mes-

            
sages are being sent, sshd will disconnect the client,
terminat-

            
ing the session.  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 mecha-

            
nism is valuable when the client or server depend on knowing

            
when a connection has become inactive.

The default value is 3.  If ClientAliveInterval
(above) is set

            
to 15, and ClientAliveCountMax is left at the default,
unrespon-

            
sive ssh clients will be disconnected after approximately 45

            
seconds.

3、echo export TMOUT=1000000
>> /root/.bash_profile; source .bash_profile

      
Linux
终端的shell环境中通过设置环境变量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

SSH会话连接超时问题的更多相关文章

  1. 解决SSH会话连接超时问题

    用SSH客户端连接linux服务器时,经常会出现与服务器会话连接中断现象,照成这个问题的原因便是SSH服务有自己独特的会话连接机制.记得在一年前就有朋友问过我这个问题,那时候我便是草草打发,结果自己现 ...

  2. 阿里云(ECS)Linux客户端SSH会话连接超时OperationTimedOut

    问题描述:使用SecureCRT等SSH客户端连接Linux服务器时,提示Operation timed out. 问题原因:SSH服务未配置或注释掉向SSH客户端连接会话发送频率和时间. 解决方法: ...

  3. 解决ssh连接超时时间(ssh timeout)的设置方法

    本文介绍下,linux中ssh连接超时时间的设置方法,以避免总是被强行退出.有需要的朋友,参考下吧.有关修改ssh连接超时时间的方法,网上介绍的很多了.比如下面这个:可以减少ssh连接超时等待的时间: ...

  4. Solaris10 如何设置空闲ssh连接超时断开

    在ssh的配置文件中有2个参数可以控制空闲连接超时断开.这2个参数是ClientAliveCountMax和ClientAliveInterval. Solaris10上设置空闲ssh连接超时断开的方 ...

  5. ssh连接超时中断问题解决方案

    当在终端使用ssh命令连接到服务器时,如果一段时间没有活动连接会被中断,以下有两种方案可以解决: 一.修改ssh客户端配置 编辑客户端 /etc/ssh/ssh_config (或~/.ssh/con ...

  6. [原]Linux ssh远程连接断开问题处理办法

    我们在通过远程连接操作Linux server的时候,有可能过一段时间忘记操作,便会发生ssh断开的问题. 而如果是本地的server,比较好办,直连设备kill掉ssh,踢掉无效用户连接,再次链接即 ...

  7. 【转】ssh timed out 超时解决方案

    转自:http://www.cnblogs.com/niutouzdq/p/4091268.html 在使用阿里云ECS服务器的时候,winsftp经常被服务器断开,想必是过一会没有操作,防火墙喜欢对 ...

  8. ssh远程连接linux服务器并执行命令

    详细方法: SSHClient中的方法 参数和参数说明 connect(实现ssh连接和校验) hostname:目标主机地址 port:主机端口 username:校验的用户名 password:登 ...

  9. SSH服务连接

    SSH基本概述 SSH是一个安全协议,在进行数据传输时,会对数据包进行加密处理,加密后在进行数据传输.确保了数据传输安全. SSH服务 ssh: secure shell, protocol, 22/ ...

随机推荐

  1. C#窗口传值(CSDN实例)

    //非模式窗体  相较独立From qform=new Form();       qform.Show(); //模式窗体  子依赖父Form qform=new Form();qform.Show ...

  2. <转>shell经典,shell十三问

    (注:关于变量概念,我们留到下两章才跟大家说明.) 好了,更多的关于 command line 的格式,以及 echo 命令的选项,就请您自行多加练习.运用了... ----------------- ...

  3. Composer创建和发送HTTP Request

    Fiddler Composer的功能就是用来创建HTTP Request 然后发送. 你可以自定义一个Request, 也可以手写一个Request, 你甚至可以在Web会话列表中拖拽一个已有的Re ...

  4. HashMap分析之红黑树树化过程

    概述 HashMap是Java程序员使用频率最高的用于映射(键值对)处理的数据类型.随着JDK(Java Developmet Kit)版本的更新,JDK1.8对HashMap底层的实现进行了优化,例 ...

  5. java基础,集合,HashMap,源码解析

    最怕,你以为你懂咯,其实你还不懂: 见贤思齐,看看那些我们习以为常的集合,通过相关定义.源码,思考分析,加深对其的理解,提高编码能力,能做一个略懂的程序员: 做几个我们常用的集合类.开篇HashMap ...

  6. Windows批量添加防火墙例外端口

    Windows下批量添加防火墙例外端口,查了网上资料,基本上都是使用"Netsh命令",循环增加端口,这会导致建立的规则特别多,不便于管理,查了下微软的资料,原来是Netsh命令, ...

  7. Fineui js getText

    需要自己写js的时候.需要取值. var ddlgenderid='<%=ddlgender.clientID%>';function reader(value){f(ddlgenderi ...

  8. python 虚拟环境--virtualenv

    virtualenv 是一个创建隔绝的Python环境的工具.virtualenv创建一个包含所有必要的可执行文件的文件夹,用来使用Python工程所需的包. 安装方式一: pip install v ...

  9. 分布式架构ActiveMQ的安装与使用(单节点)

    具体内容请参考样例代码和视频教程: http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53   IP:192.168.4. ...

  10. Asp.net SignalR 让实时通讯变得简单

    巡更项目中,需要发送实时消息,以及需要任务开始提醒,于是便有机会接触到SignalR,在使用过程中,发现用SignalR实现通信非常简单,下面我思明将从三个方面分享一下: 一.SignalR是什么 A ...