5 Easy Ways to Fix SSH Keep Alive Disconnection in 2026

Ever been knee-deep in a server migration, only to watch your SSH session freeze and drop mid-command? Yeah. Annoying doesn’t even cover it. That’s the classic SSH keep alive disconnection problem — and the fix is way easier than most tutorials make it sound.

The short version: most firewalls and NAT routers silently kill idle connections after 60–300 seconds. Your SSH session looks “dead” to them, so they drop it without telling either side. The trick is sending tiny keepalive packets so the connection always looks alive. Here’s how to actually do it in 2026, on every platform you’re likely to touch.

Why SSH Sessions Keep Dying (The Real Cause)

Quick theory, then we get to the fixes. When you connect through a home router, corporate firewall, or CGNAT, that device keeps a table of active connections. Idle TCP sessions get evicted to free up memory — usually without sending a TCP RST. Your terminal just… hangs.

Three common killers:

  • NAT timeout — home routers often drop idle connections after ~60 seconds
  • Firewall state expiry — enterprise firewalls, same behavior, longer timers
  • Server-side ClientAliveInterval — the server itself giving up on a silent client

From my experience troubleshooting reader setups over the years, NAT timeout is the culprit about 80% of the time. Fun fact: it’s not your ISP “blocking” you. It’s just housekeeping.

Fix #1: Client-Side KeepAlive (The 2-Minute Solution)

This is the one you should try first. Edit (or create) ~/.ssh/config on your local machine and add:

Host *

  ServerAliveInterval 60

  ServerAliveCountMax 3

  TCPKeepAlive yes

What this does: every 60 seconds, your client sends an encrypted keepalive probe through the SSH channel. If three probes go unanswered, only then does it give up. That’s smart keepalive — it detects a genuinely dead server instead of hanging forever.

On Windows? OpenSSH ships with Windows 10/11, so the same config works in C:Usersyou.sshconfig. PuTTY users: go to Connection, set “Seconds between keepalives” to 60, and tick “Enable TCP keepalives.”

Fix #2: Server-Side Configuration

If you control the server, you can make it request keepalives too — useful when the client is someone else’s machine you can’t configure. Edit /etc/ssh/sshd_config:

ClientAliveInterval 60
Learn more about Fix V2RayNG Connection Failed in 2026.

ClientAliveCountMax 3

Then reload the daemon: sudo systemctl reload sshd. Done. New sessions pick it up immediately (existing ones won’t — reconnect).

Jadi gini — wait, wrong language, force of habit from my other articles. Simply put: client-side fixes your sessions, server-side fixes everyone else’s. If you run a VPS that teammates also SSH into, do both.

Fix #3: Taming Aggressive Routers and Firewalls

Sometimes 60 seconds isn’t enough. Public Wi-Fi, hotel networks, and some mobile carriers drop idle connections in as little as 30 seconds. Drop your interval to 15–30:

ServerAliveInterval 15

The overhead is negligible — a keepalive packet is tiny, and at one per 15 seconds you’re sending maybe 4KB per hour. Nobody will notice. Your battery won’t either.

When mosh beats everything

Honestly, if your connection is genuinely flaky — think train Wi-Fi or a VPN premium tunnel that renegotiates often — skip keepalive tuning entirely and use mosh. It survives IP changes, sleeps, and roaming. Install it on both ends (sudo apt install mosh), open UDP ports 60000–61000, and connect with mosh user@server. It’s not a drop-in SSH replacement (no port forwarding), but for interactive shell work it’s overrated-proof and just works.

Fix #4: Tunneling Apps and Mobile Setups

Running tunnels through apps like HTTP Injector, v2rayNG, or NekoBox? Same principle applies, but the setting hides in different places:

  • v2rayNG / NekoBox — enable “mux” or set connection heartbeat in the transport settings
  • WireGuard — add PersistentKeepalive = 25 under the peer section. This one’s mandatory behind NAT; 25 seconds is the officially recommended value
  • HTTP Injector — check the keep-connected / auto-reconnect options in connection settings

For WireGuard specifically, without PersistentKeepalive, an endpoint behind NAT becomes unreachable until the client sends traffic again. That one line fixes a whole category of “my tunnel died overnight” reports.

Fix #5: Infrastructure-Level Tweaks

Working from a laptop terbaik-tier machine on a flaky hotel network and still dropping? Sometimes the fix isn’t SSH at all — it’s your path. A few things worth checking: For more on this, see SSH Slow Speed? 5 Fixes to.

  1. Use SSH over port 443 if your server supports it — many networks treat 22 harshly
  2. Run SSH inside tmux or screen — even if the session drops, your work survives. This is the real pro move. tmux attach and you’re back
  3. Check your hosting — some budget providers have aggressive idle-killing on their edge. Honestly, moving to a hosting terbaik candidate with proper TCP handling solved this permanently for one of my staging servers

Tip: keep a spare lightweight VPS (the kind you’d pair with a domain murah setup) as a jump host. Stable entry point, and your long sessions live there instead of on fragile local connections.

Extra Tips Most Guides Skip

A few things I’ve learned the hard way:

  • Escaped keepalive trick: typing ~V inside an SSH session (then Enter) forces a version negotiation packet — sometimes wakes a half-dead session
  • Don’t set intervals too low. Under 10 seconds and some firewalls flag you as beaconing. 15–60 is the sweet spot
  • Autosave your work. Even with perfect keepalive, pair it with tmux. Belt and suspenders
  • Log it. Run SSH with ssh -v once to see exactly where the connection dies — client, network, or server. Two minutes of reading saves hours of guessing

Satirical side note: if your sessions only die during team calls, check whether your aplikasi produktivitas video app is saturating upstream and starving keepalive probes. Correlation isn’t causation… except when it is.

FAQ

Does keepalive traffic count against bandwidth caps?

Practically no. A keepalive probe is under 100 bytes. Even at 15-second intervals, you’re looking at kilobytes per hour. Negligible.

Should I set ServerAliveInterval on the server instead?

Different setting — ClientAliveInterval is the server-side equivalent. Client-side is usually enough and doesn’t require admin rights. Do server-side only when you manage many users.

Why does my session still freeze even with keepalive?

Then the drop is likely upstream of NAT — packet loss or a broken middlebox. Run mosh or work inside tmux, and test with mtr to find where packets die.

Is TCPKeepAlive yes dangerous?

Slightly. It uses TCP-level probes, which can be spoofed, and it can’t distinguish a dead network from a dead server. That’s why ServerAliveInterval (encrypted, application-level) is the better primary setting.

The Bottom Line

Set ServerAliveInterval 60 in your SSH config right now — it takes two minutes and fixes most disconnections permanently. Add tmux for insurance, and mosh if your network is truly hostile.

And if you want a tunneling setup where keepalive headaches are handled for you out of the box, try a free account at claudessh.com — no config gymnastics required. Your long-running sessions will thank you.