Is it possible to detect the activity of the ssh connection when the connection is broken. I connect to the server via phone (ssh client) and turn off the internet, but the system (w, netstat) says I'm still on the server. Is it possible to immediately determine the activity or wait for a timeout?
-
A broken connection can be detected only when data is sent. See https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/ – Bodo Dec 15 '22 at 17:22
1 Answers
For the server see man 5 sshd_config
, options ClientAliveInterval
and ClientAliveCountMax
. If you want the server to detect when a connection breaks then you need to use these options in /etc/ssh/sshd_config
on the server machine.
For the client see man 5 ssh_config
, options ServerAliveInterval
and ServerAliveCountMax
. If you want the client to detect when a connection breaks then you need to use these options in /etc/ssh/ssh_config
or in ~/.ssh/config
on the client machine, or in the command line while starting the connection (ssh -o ServerAliveInterval=… -o ServerAliveCountMax=…
).
Read this another answer of mine, it elaborates and gives few interesting links. Note the OP there wants to disconnect an idle user (which is not a job for ClientAlive*
/ServerAlive*
mechanisms), while you want to detect a broken connection (which is exactly the job of the mechanisms).

- 21,864