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

怼烎@ 2023-06-01 12:37 101阅读 0赞

这点可以参考之前的一篇文章:ssh连接超时(ssh的usedns选项)的解决办法 。
再来看,设置ssh超时时间的方法。
修改自己 root 目录下的.bash_profile文件,加上
export TMOUT=1000000 (以秒为单位)
然后运行:

  1. source .bash_profile
  2. 在/etc/ssh/sshd_config中加入:
  3. ClientAliveInterval=60

每一分钟,sshd都和ssh client打个招呼,检测它是否存在,不存时即断开连接。

注意:设置完成后,要退出ssh远程连接,再次登录后才可以生效。因为要再读取一次./bash_profile。
为了方便,将设置写成了如下脚本:

  1. echo export TMOUT=1000000 >> /root/.bash_profile
  2. cat /root/.bash_profile
  3. source .bash_profile
  4. cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
  5. echo ClientAliveInterval=60 >> /etc/ssh/sshd_config
  6. service sshd restart
  7. cat /etc/ssh/sshd_config
  8. service sshd restart
  9. exit

总结:

在ClientAliveInterval(/etc/ssh/sshd_config)、环境变量TMOUT(在/etc/profile或.bash_profile中设置)以及putty的”Seconds between keepalives“这些方法中,经
检测,只有TMOUT可以控制ssh连?在空闲时间超时,自动断开连接的时间,数字单位为“秒”。
在设置了TMOUT后(非0),另外两个变量则不起作用的。

转载于:https://www.cnblogs.com/beautiful-code/p/11265435.html

发表评论

表情:
评论列表 (有 0 条评论,101人围观)

还没有评论,来说两句吧...

相关阅读