How do I reduce idle SSH disconnects?
Client keepalive messages can help detect broken connections and may keep some idle network mappings active. They do not guarantee that a firewall will allow an indefinitely idle session, and they do not preserve jobs across server reboots.
Instructions
1. Try a connection-specific keepalive
Use a moderate interval before changing a reusable host profile.
ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3 adminuser@203.0.113.10The client sends an encrypted liveness request after the configured inactivity interval and closes an unresponsive connection after the allowed unanswered checks.
2. Separate policy from a broken path
If the server deliberately enforces session limits, keepalives may not change that policy. Check whether the disconnection coincides with VPN changes, laptop sleep, network switching or a service restart.
3. Preserve work with the appropriate server mechanism
For an interactive Linux task that should survive a network disconnect, consider an approved tmux session. For a production application, use its normal service manager. Keepalive settings are connection management, not a replacement for either.
Check the result
- The session remains usable through the previously observed idle period when policy permits.
- A real connection failure is detected instead of leaving an apparently live but frozen terminal.
Troubleshooting
- Disconnects continue at an exact duration
- Check server and network session policies with the administrator.
- The laptop sleeps
- A sleeping computer cannot maintain its network connection. Resume and reconnect to an approved persistent remote session.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
