Operations 3 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Keep SSH Sessions Alive by Editing the SSH Config

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 60

Ensure 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 60

Result

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxNetworkingSystem AdministrationSSH
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.