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?

  • After changing config on server did you restart sshd? Commented May 26, 2018 at 20:12
  • @RomeoNinov yes. Even server
    – Baterka
    Commented May 26, 2018 at 20:13
  • 4
    The connection drops when it's idle? Are you behind a NAT? Is it possible that there's a router that could be dropping inactive connections?
    – ilkkachu
    Commented May 26, 2018 at 20:36
  • 1
    Did you set ClientAliveInterval and ClientAliveCountMax in the sshd_config. Also what client are you using to connect to the server? Commented May 26, 2018 at 22:20
  • @ilkkachu I am using some Asus Wifi router. I dont think so its because router... Connection was not deopping last fee months.
    – Baterka
    Commented May 28, 2018 at 10:14

2 Answers 2


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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .