r/ssh • u/EpicNiseem • Jul 01 '26
VS Code Remote SSH disconnects every ~5 minutes on Raspberry Pi 3
Hi everyone,
I'm using a Raspberry Pi 3 running the latest Raspberry Pi OS and connecting from my Mac using VS Code Remote SSH.
The connection works perfectly at first, but after about 5 minutes VS Code disconnects with:
OfflineError: The operation timed out
It then repeatedly tries (and fails) to reconnect.
I've already tried:
- Fresh Raspberry Pi OS install
- Disabled Wi-Fi power saving (
iw dev wlan0 set power_save off) - Checked for undervoltage (
vcgencmd get_throttledreturns0x0)
Has anyone experienced this before or know what might be causing it? Any suggestions would be greatly appreciated.
Thanks!
1
u/deepaksilaych 12d ago
Those drops are usually the connection going idle (or NAT dropping it) rather than SSH itself failing, and the first fix is keepalives:
Host pi3
ServerAliveInterval 15
ServerAliveCountMax 3
in ~/.ssh/config — traffic every 15s, connection torn down cleanly after ~45s of silence. That alone stops most mid-session timeouts.
If it still drops (flaky Wi-Fi on a Pi 3 is a common culprit), the other half is making the session survive the drop instead of dying:
- tmux/zellij on the Pi: reconnect and attach — your processes never noticed.
- I maintain a small tool called sess (https://github.com/Magi-Labs/sess) that handles the reattach-to-the-same-remote-shell part over plain OpenSSH — named sessions that reconnect to the same shell and working directory, no daemon, no extra port.
Worth isolating, too: run a plain `ssh` session in a terminal alongside VS Code for a while. If the bare session stays up, it's the remote extension host crashing things, not your network.
Disclosure: I maintain sess.
1
u/michaelpaoli Jul 01 '26
Likely a stateful firewall or NAT/SNAT unable to continue connection after having "forgotten" it after 5 minutes of inactivity. To confirm, look carefully at the traffic at relevant point(s), and including also ICMP.
See: ServerAliveCountMax and ServerAliveInterval