ssh连接超时的解决办法

Posted CaoDavidgogo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ssh连接超时的解决办法相关的知识,希望对你有一定的参考价值。

ssh连接超时的解决办法

设置ssh超时时间的方法。

这个应该是在server端修改
修改自己 root 目录下的.bash_profile文件,加上
export TMOUT=1000000 (以秒为单位)
然后运行:

source .bash_profile
在/etc/ssh/sshd_config中加入:
ClientAliveInterval=60
每一分钟,sshd都和ssh client打个招呼,检测它是否存在,不存时即断开连接。

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

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
总结:

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

更多信息:
了解更多ssh_timeout_in_linux
如何增加ssh timeout时间 increase linux ssh connection timeout quick guide
setup ssh keys to login linux without password

以上是关于ssh连接超时的解决办法的主要内容,如果未能解决你的问题,请参考以下文章

从SecureCRT连接到虚拟机失败。提示连接超时。求解决办法。200分。

SSH超时断开(ClientAliveInterval和ClientAliveCountMax )的使用

解决 FileZilla 20秒连接超时问题. (SSH + sftp协议)

如何解决SSH连接Linux超时自动断开

如何解决SSH连接Linux超时自动断开

Putty解决SSH连接超时断开的问题