配置linux登录超时命令,LINUX中 设置登录超时

ssh设置超时时间

ssh连接超时问题解决方案:

1.修改server端的etc/ssh/sshd_config

ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后client响应,从而保持连接

ClientAliveCountMax 3 #server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应

2.修改client端的etc/ssh/ssh_config添加以下:(在没有权限改server配置的情形下)

ServerAliveInterval 60 #client每隔60秒发送一次请求给server,然后server响应,从而保持连接

ServerAliveCountMax 3  #client发出请求后,服务器端没有响应得次数达到3,就自动断开连接,正常情况下,server不会不响应

3.另一种方式:

不修改配置文件

在命令参数里ssh -o ServerAliveInterval=60 这样子只会在需要的连接中保持持久连接, 毕竟不是所有连接都要保持持久的

=====================补充========================

keeping your ssh session alive through

pesky(讨厌的,麻烦的) NAT firewalls.

NAT firewalls like to time out idle sessions to keep their state tables clean and their memory footprint low.

NAT防火墙喜欢对空闲的会话进行超时处理,以确保它们状态表的干净和内存的低占用率。

Some firewalls are nice, and let you idle for up to a day or so; some are gestapo and terminate your session after 5 minutes.

一些防火墙比较友好,允许你的空闲会话时间为一天甚至超过一天;另一些却如盖世太保,5分钟空闲就终止你的会话。

I finally got tired of my ssh sessions getting disconnected at places where I don't control the firewalls, and figured out how to stop it.

我最终疲于我的ssh连接会话被我不能控制的防火墙断开,并找出了阻止它的方案。

Turn out ssh has a nice inband keepalive mechanism, and even lets you set it on a per-destination basis.

结论是ssh内带有一个很好的保持会话存活机制,甚至允许你在每一台目标机器上设置。

Just create a ~/.ssh/config file with something like the following (* will match any host, if you wanted you could restrict this to particular destinations like *kehlet.cx):

只要用以下类似的内容创建一个 ~/.ssh/config文件(*号将匹配所有的主机,如果你想,你可以严格的设置它为特定的目标主机,像kehlet.cx):

----------------

Host *

ServerAliveInterval 240

----------------

That's how often, in seconds, ssh will send a keepalive request (at the application layer) to the other end if the connection's been otherwise idle. 4 minutes should be good :-).

这通常是以秒为单位,如果这个连接空闲,ssh将发送一个保持存活的请求(在应用层)给另一端。4分钟应该不错。

The Host line lets you pattern match your destinations. Minimal effort, no impact to your system (say, as you would have if you mucked with your system's default TCP keepalive settings), and it works like a charm.

Host行使你匹配你的目标主机。极小的努力,对你的系统毫无影响(即,如果你弄乱你的系统默认TCP保持存活时间设置的话,将影响你的系统),并且很有效。

============================================

方案二    LINUX中设置登录超时

============================================

我的LINUX系统使用SSH2登录,一直想设登录超时,即有60秒没有做任何操作就自动注销,以前一直在SSH2的配置里找,总没有设置成功,后来终于发现其实在shell里设置就行了,可以编辑/etc/profile文件,在里面加上一句TMOUT=60之后重新登录就可以了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值