代码之家  ›  专栏  ›  技术社区  ›  Gaurang Shah

10分钟后使用ssh超时执行远程脚本

ssh
  •  0
  • Gaurang Shah  · 技术社区  · 6 年前

    SSH

    它在大多数情况下都工作得很好,但是我有一个脚本,它的不活动时间超过10分钟,我与远程机器的连接丢失。

    test.sh

    echo "testing"
    sleep 3600
    echo "done testing"
    

    这就是我对这个脚本的称呼

    ➜  ~ ssh -o ConnectTimeout=3600 -o BatchMode=yes -o StrictHostKeyChecking=no gaurang.shah@host_name /home/gaurang.shah/test.sh
    *******************************************************************************
    *                                                                             *
    *          Unauthorized use of this system is strictly prohibited             *
    *                                                                             *
    *******************************************************************************
    
    testing
    Connection to host_name closed by remote host.
    

    此参数不应该使连接保持活动状态3600秒吗?

    -o连接超时=3600

    1 回复  |  直到 6 年前
        1
  •  0
  •   gile    6 年前

    ConnectTimeout 指定连接到SSH服务器时使用的超时(秒)

    你必须把它设置好 ServerAliveInterval 相反要为所有用户设置它,您必须修改 /etc/ssh/ssh_config (有根授权)。要仅启用您的用户,请修改 ~/.ssh/config

    Host *
        ServerAliveInterval 3600
        ServerAliveCountMax 2
    

    如果可以修改服务器端,则可以通过将以下内容添加到 /etc/ssh/sshd_config

    ClientAliveInterval 3600
    ClientAliveCountMax 2