这点能够参考以前的一篇文章:ssh链接超时(ssh的usedns选项)的解决办法 。
再来看,设置ssh超时时间的方法。
修改本身 root 目录下的.bash_profile文件,加上
export TMOUT=1000000 (以秒为单位)
而后运行:bash
source .bash_profile 在/etc/ssh/sshd_config中加入: ClientAliveInterval=60
每一分钟,sshd都和ssh client打个招呼,检测它是否存在,不存时即断开链接。ssh
注意:设置完成后,要退出ssh远程链接,再次登陆后才能够生效。由于要再读取一次./bash_profile。
为了方便,将设置写成了以下脚本:spa
echo export TMOUT=1000000 >> /root/.bash_profile cat /root/.bash_profile source .bash_profile cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak echo ClientAliveInterval=60 >> /etc/ssh/sshd_config service sshd restart cat /etc/ssh/sshd_config service sshd restart exit
总结:rest
在ClientAliveInterval(/etc/ssh/sshd_config)、环境变量TMOUT(在/etc/profile或.bash_profile中设置)以及putty的"Seconds between keepalives“这些方法中,经
检测,只有TMOUT能够控制ssh连?在空闲时间超时,自动断开链接的时间,数字单位为“秒”。
在设置了TMOUT后(非0),另外两个变量则不起做用的。code