I am using an ssh tunnel for port forwarding via the command ssh -fN -R *:443:localhost:443 <public server>
Sometimes, the ssh process on the client dies (presumably connection timeout), so I have set up a script that tries to reconnect to the server. However, this sometimes fails, as the corresponding sshd
process on the server lives on and occupies the port despite the fact that the connection died.
I want the server process to detect this and die as well. I have tried adding the following lines to the server's /etc/ssh/sshd_config
to no avail:
ClientAliveInterval 30
ClientAliveCountMax 3
With these settings, I would expect the server process to die within two minutes of the client process dying, but it's still going some 10 minutes after. When I ran netstat -p
on it, the tunnel connection looks like this:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 18584 <Hostname>:ssh <ip>:54208 ESTABLISHED 962/sshd: root
Is there anything else besides the ClientAlive
settings I can do to make sure the server process detects the dropped connection and dies as well, freeing up the port for connection reestablishment?