How to avoid timeouts while you are logged on SSH

Are you having issues with constant disconnections on SSH? Here is the guide for you.

5 months ago   •   1 min read

By Aquasp
Table of contents

Introduction

One of the most frustrating things when working on a server?

Your SSH session dies because of a brief Wi-Fi hiccup, idle timeout, or flaky connection.

Fix it forever in 30 seconds.

The Universal Fix: Edit Your SSH Config

This works on Linux, macOS, and Windows — and survives network glitches up to ~4–5 minutes.

Step 1: Create or Edit the SSH Config File

On Linux / macOS:

mkdir -p ~/.ssh
nano ~/.ssh/config

On Windows (PowerShell):

# Replace YourUsername with your actual Windows username
mkdir "$HOME\.ssh" -Force
notepad "$HOME\.ssh\config"

Step 2: Add These Lines

sshHost *
    ServerAliveInterval 120
    ServerAliveCountMax 3
    TCPKeepAlive yes

Save and exit.

Done. That’s it.

What This Actually Does

SettingMeaning
Host *Apply these rules to every SSH connection
ServerAliveInterval 120Every 2 minutes, your computer sends a tiny “I’m still here” packet
ServerAliveCountMax 3If 3 packets in a row fail → only then close the connection (~6 min)
TCPKeepAlive yesExtra OS-level keepalive (helps with some routers/firewalls)

Result: Your SSH session now survives:

  • Wi-Fi switching
  • Laptop sleep/wake
  • Brief internet drops
  • VPN reconnects

…without freezing or dying.

You're Now Unbreakable

From now on, when your internet blinks, your SSH session just… waits patiently.

No more “Connection reset by peer”
No more lost tmux sessions
No more rage

You’ve officially leveled up.

If this saved your sanity, share it with a fellow admin or subscribe to The Self Hosting Art.

Thank you for reading — stay connected!

Spread the word

Keep reading