“connection refused” on ssh reverse tunnel

ssh-tunnel

I have a single remote server with two (server) clients connecting using autossh -nNT -R ... Each client has a separate inbound port into the remote server. If I reboot the clients, I will get a connection refused message when attempting to reconnect from my local PC.

When I issue netstat | grep ssh on the remote server, I see multiple "ESTABLISHED" ssh connections. If I then issue a sudo pkill --signal HUP sshd on the server and then attempt to reach the clients that are configured to run autossh via the server (from my local PC), the connections succeed. I believe that when a client connection established through autossh is broken, it is unable to reestablish the connection. At first I thought it was the TCPKeepAlive/ClientAliveInterval settings in sshd_config may've been affecting resources, so I commented them out and rebooted the server, but I am still observing the behavior.

/var/log/messages on the client seems to be filled with ssh exited with error status 255; restarting ssh while the connection refused condition exists.

What can I do to ensure that when a client connection is no longer active that the server frees resources in a timely manners so that the client can reestablish the connection?

Best Answer

Have you tried changing on the Server /etc/ssh/sshd_config these parameters?

  • ClientAliveCountMax
  • ClientAliveInterval

From http://man.openbsd.org/sshd_config

enter image description here