Why Does SSH Close the Connection?

TCP timeouts. TCP timeout refers to the duration that a TCP connection or a network operation waits for a response before considering the process failed. These limitations can be altered.

Three variables are important:

tcp_keepalive_time is the remaining idle time before sending probes (small packets sent by system to check if the connection is still active)

tcp_keepalive_probes holds the amount of keepalive probes TCP sends before considering the connection as "lost”

tcp_keepalive_intvl controls the interval between sending keepalive probes on an idle TCP connection.

Untitled

Configuration

Keeping an SSH session alive is a process that involves configuration on both the client and server sides.

Modify either /etc/ssh/ssh_config (system-wide) or ~/.ssh/config ****(user)

mkdir ~/.ssh && ****chmod 700 ~/.ssh if directory does not exist

Host *
    ServerAliveInterval 120
    ServerAliveCountMax 30
TCP Parameter SSH Configuration Option
tcp_keepalive_time ServerAliveInterval
tcp_keepalive_probes ServerAliveCountMax
tcp_keepalive_intvl No direct equivalent