Skip to content

antony@notes:~/misc$ cat "Increase-SSH-Connection-Timeout-in-Linux.md"

Increase SSH Connection Timeout in Linux

2024-01-02· misc ·Linux

Increase SSH Connection Timeout in Linux

1. SSH Server 設定

$ cat <<EOF | sudo tee -a /etc/ssh/sshd_config
ClientAliveInterval 1200
ClientAliveCountMax 9
EOF

The ClientAliveInterval parameter specifies the time in seconds that the server will wait before sending a null packet to the client system to keep the connection alive.

the ClientAliveCountMax parameter defines the number of client alive messages which are sent without getting any messages from the client. If this limit is reached while the messages are being sent, the sshd daemon will drop the session, effectively terminating the ssh session.

Timeout value = ClientAliveInterval * ClientAliveCountMax

以上設定等於連續連接 9 小時都沒發送命令後才會斷線

2. 重啟 SSHD 服務

$ sudo systemctl restart sshd