2
1
How I can detect when a SSH client disconnects from my server? If the connection with the client is interrupted (the client doesn't send the disconnection command), my server application receives character 0xFF through standard input. I try using KeepAlive and ClientAlive parameters in sshd_config but the connection never closes (I don't receive any signal like SIGHUP, SIGTERM or any other).
On the other hand, how can I close a hung connection? There are several connections established and the others work well. Restarting the SSH server is not the solution.
How exactly is the ssh client connecting to your application? – Kenster – 2014-08-12T21:14:54.223
You could try increasing the verbosity in which sshd (or whatever ssh daemon you use) logs events and if you're open to it, parse through the system log for those events that indicate the events you are looking for. – James Lui – 2014-08-12T21:26:30.240
Doesn't matter how the client connects. Even if i use linux ssh client connecting to localhost. – mauricio – 2014-08-13T12:36:18.603
>Log said:
sshd[26227]: Accepted keyboard-interactive/pam for xxxxx from 10.0.0.1 port 47537 ssh2 sshd[26227]: pam_unix(sshd:session): session opened for user xxxxx by (uid=0) -- sshd[26230]: Received disconnect from 10.0.0.1: 11: disconnected by user sshd[26227]: pam_unix(sshd:session): session closed for user xxxxx -- And, of course, any signal received... – mauricio – 2014-08-13T12:37:45.080
If i send SIGHUP (or any other) signal to my application running, the program exits (i put the code to trap them) and the session ends. – mauricio – 2014-08-13T12:45:21.503
1I have a funny feeling that you're not really getting 0xFF, but that your read is returning -1 (EOF), which you're casting to an unsigned char, giving 0xFF. Please check your code and rule out this possibility. – aecolley – 2014-08-13T20:15:14.903