How to Keep SSH Sessions Alive by Editing the SSH Config
This guide explains how to prevent idle SSH sessions from being terminated by adding a ServerAliveInterval setting to the user‑level or system‑wide SSH configuration files, ensuring the connection stays alive without compromising security.
Background
SSH clients often terminate idle sessions after a few minutes for security reasons.
Solution
Modify the SSH client configuration to send periodic keep‑alive messages.
Per‑user configuration
Create or edit ~/.ssh/config and add the following lines:
Host *
ServerAliveInterval 60Ensure the second line starts with a space. The asterisk ( *) applies the setting to all remote hosts; replace it with a specific hostname or IP address to target a single server.
System‑wide configuration
To apply the setting for all users, edit /etc/ssh/ssh_config and add the same lines:
Host *
ServerAliveInterval 60Result
With ServerAliveInterval set, the SSH client sends a keep‑alive packet every 60 seconds, preventing the session from being closed due to inactivity.
Warning
Only change SSH behavior if you understand the implications and are certain it will not cause issues in your environment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
