2

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.

6
  • How exactly is the ssh client connecting to your application?
    – Kenster
    Aug 12, 2014 at 21:14
  • 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
    Aug 12, 2014 at 21:26
  • Doesn't matter how the client connects. Even if i use linux ssh client connecting to localhost.
    – mauricio
    Aug 13, 2014 at 12:36
  • 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
    Aug 13, 2014 at 12:37
  • 1
    I 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
    Aug 13, 2014 at 20:15

0

You must log in to answer this question.

Browse other questions tagged .