Idle SSH sessions often disappear when a firewall, NAT device, or VPN path removes a quiet connection before the remote shell is finished. Enabling client keepalive makes the local SSH client send periodic protocol-level checks so an otherwise healthy session is less likely to be dropped just because it sat idle for a while.
The OpenSSH client reads command-line options first, then ~/.ssh/config, then /etc/ssh/ssh_config, and uses the first value it gets for each setting. A Host block matches the host name or alias used on the ssh command line, so host-specific entries should appear before broader defaults such as Host *. ServerAliveInterval sends an encrypted check only after the server has been silent for the chosen number of seconds, while ServerAliveCountMax limits how many missed replies are allowed before the client closes the session.
Current OpenSSH clients still leave ServerAliveInterval disabled by default even though TCPKeepAlive remains enabled. That means idle-session protection does not start until a keepalive interval is configured. Check the merged settings with ssh -G before reconnecting, and if the session still drops at the same fixed timeout, the limit is likely being enforced by the server or a network policy instead of the client.
$ mkdir -p ~/.ssh $ chmod 700 ~/.ssh
OpenSSH can ignore per-user configuration or key files when the directory is writable by other users.
$ nano ~/.ssh/config
Use /etc/ssh/ssh_config only when the same keepalive policy must apply to every user on the machine.
Host host.example.net ServerAliveInterval 60 ServerAliveCountMax 3
Replace host.example.net with the host name, IP address, or alias used on the ssh command line.
With ServerAliveInterval 60 and ServerAliveCountMax 3, the client closes the session after about three minutes if the server stops answering keepalive requests.
Use Host * instead of a named destination only when every SSH connection from this client should inherit the same keepalive values.
$ ssh -G host.example.net ##### snipped ##### hostname host.example.net tcpkeepalive yes serveralivecountmax 3 serveraliveinterval 60 ##### snipped #####
ssh -G prints the effective configuration after evaluating the matching Host and Match blocks, then exits.
If serveraliveinterval still shows 0, the wrong host name matched or a broader block took precedence earlier in the file.
$ ssh host.example.net
Client keepalive cannot override a server policy that deliberately closes idle sessions after a fixed limit. If the connection still drops at the same exact timeout, inspect the server-side timeout settings instead.