【MobaXterm】设置保持SSH连接

ssh远程连接会在无操作时自动断开连接。为了保持程序运行和连接,需要设置保持连接。

1.MobaXterm

如果使用了MobaXterm客户端,那么需要在设置里点选setting>SSH>sessions setting>勾选ssh Keepalive

  • keepalive
    在这里插入图片描述
    选择下图的选项即可:
    在这里插入图片描述

2.SSH

如果使用的是ssh则需要设定超时连接的时间/etc/ssh/sshd_config

  • 服务器端要设置客户的超时重连:
ClientAliveCountMax 3    #默认重连3次
ClientAliveInterval 30   #30s重连一次
  • 客户端要设置服务器端的超时重连(user 设置文件在~/.ssh/下):
ServerAliveCountMax 3
ServerAliveInterval 30

重启服务service sshdservice sshd restart

另一种很直接的方法,直接使用ssh命令参数:
ssh -o ServerAliveInterval 30将超时重连传进去。
在这里插入图片描述
icon from easyicon


ref:
ssh:https://www.ssh.com/ssh/sshd_config/
openssh:http://www.jinbuguo.com/openssh/sshd_config.html
mobaxterm:https://mobaxterm.mobatek.net/documentation.html#6_8_4
https://blog.csdn.net/yelllowcong/article/details/76850708
https://blog.csdn.net/abld99/article/details/69388858

原文地址:https://www.cnblogs.com/Tom-Ren/p/10024299.html