11

I am connected to my Debian 9 with Virtualmin by SSH from my PC. I go for +-2 minutes away and after I return, SSH is disconnected... I tried changing ssh config on server and on client... Nothing helped... Where to search for problem? Can it be some settings of networking or maybe router?

Baterka
  • 303

2 Answers2

21

Some over-zealous routers like to drop TCP connections that are idle for too long (i.e. don't transmit any data). It might be because they assume the user only uses things like HTTP, where the connection is often closed after a single query is complete.

Assuming OpenSSH, use the ClientAliveInterval and ClientAliveCountMax directives in sshd_config, or equivalently ServerAliveInterval and ServerAliveCountMax in the client side config (~/.ssh/config or /etc/ssh/ssh_config) to enable protocol-level keepalive packets.

They're actually meant to detect if the remote host has gone away, but since they cause messages to be sent when the connection is otherwise idle, they also work to prevent the connection from being seen as idle by outside devices.

*AliveInterval sets the interval (in seconds) after which the client/server sends a query to the remote, and *AliveCountMax sets the number of unanswered queries after which the the client/server drops the connection as inactive.

Something like these values should do:

ClientAliveInterval 15
ClientAliveCountMax 4
ilkkachu
  • 138,973
1

My Asus DSL-N66U has done this to me for years, and today I found a setting that fixed my problem. So I wanted to detail the issue and fix somewhere on the internet in the hopes that someone else may find it.

I host a local server that has SSH, HTTP, HTTPS, IMAP, IMAPS, SMTP, SMTPS, MQTT all port forwarded / pinholed.

I have a static IP and a domain name associated with my static IP so its a regular home server with a domain name.

When ever I connected to my server using my domain name from within my internal network, the connection would get dropped after soeme time. This made it impossible to use SSH, IMAP, MQTT or anything that keeps a socket open. The the solution on the Asus DSL-N66U was to change:

LAN -> Switch Control -> NAT Acceleration to Disabled