sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
3.9k stars 921 forks source link

[feature] respond to server check alive requests #709

Open abdeldjalil-fellah opened 4 years ago

abdeldjalil-fellah commented 4 years ago

when the ssh server is configured to check clients alive status with: ClientAliveCountMax 2 ClientAliveInterval 5

the client should reply to the server requests to prevent the server from terminating the session but it does not as you can see in this server log:

 Jul 23 11:24:09 localhost sshd[5270]: debug3: send packet: type 81 [SSH_MSG_REQUEST_SUCCESS]
 Jul 23 11:24:09 localhost sshd[5270]: debug3: send packet: type 80 [SSH_MSG_GLOBAL_REQUEST]
 Jul 23 11:24:14 localhost sshd[5270]: debug3: send packet: type 80 [SSH_MSG_GLOBAL_REQUEST]
 Jul 23 11:24:19 localhost sshd[5270]: Timeout, client not responding from user user1 192.168.43.253 port 51236

with putty the server logs:

 Jul 23 11:44:20 localhost sshd[5364]: debug3: send packet: type 99 [SSH_MSG_CHANNEL_SUCCESS]
 Jul 23 11:44:20 localhost sshd[5360]: debug3: mm_request_receive entering
 Jul 23 11:44:20 localhost sshd[5360]: debug3: monitor_read: checking request 124
 Jul 23 11:44:25 localhost sshd[5364]: debug2: channel 2: request keepalive@openssh.com confirm 1
 Jul 23 11:44:25 localhost sshd[5364]: debug3: send packet: type 98 [SSH_MSG_CHANNEL_REQUEST]
 Jul 23 11:44:25 localhost sshd[5364]: debug3: receive packet: type 100 [SSH_MSG_CHANNEL_FAILURE]
 Jul 23 11:44:25 localhost sshd[5364]: debug1: Got 100/12 for keepalive
 Jul 23 11:44:30 localhost sshd[5364]: debug2: channel 2: request keepalive@openssh.com confirm 1
 Jul 23 11:44:30 localhost sshd[5364]: debug3: send packet: type 98 [SSH_MSG_CHANNEL_REQUEST]
 Jul 23 11:44:30 localhost sshd[5364]: debug3: receive packet: type 100 [SSH_MSG_CHANNEL_FAILURE]
 Jul 23 11:44:30 localhost sshd[5364]: debug1: Got 100/13 for keepalive

PS: does the client respond to tcp_keepalive messages (TCPKeepAlive yes)?

JustinGrote commented 4 years ago

I had the same issue trying to use with SISH which requests server keepalives. Both Putty and Openssh respond to the keepalives appropriately.

JustinGrote commented 4 years ago

@jalil1408 I am a C# noob but I managed to cobble together something that works. Attached is a patched zip of netstandard2.0 binaries. Renci.SshNet-netstandard20-ServerKeepAliveResponse.zip