I'm using a reverse ssh tunnel from home to work, so I can check my home PC every now and then during working hours, all without the need of opening my home router for incoming connections.
Both PC's (home and work) are running Linux (however, different distros).
I'm running the ssh command on my home PC in a loop (I need the connection for VNC access only):
while [ true ] do date ssh -T -N -R 15900:localhost:5900 me@work-PC sleep 5m done
And on the work PC, I connect the VNC viewer to localhost:15900.
This is my .ssh/config on my home PC:
host work-PC ProxyJump employers-Gateway HostName work-PC User me host employers-Gateway HostName web.company.com User me
It works fine as long as the ProxyJump (employers-Gateway) is not rebooted. When I reboot the work-PC, the ssh connection ends (as expected) and a new one is opened after 5 minutes. But when the employers-Gateway is rebooted, the connection just gets stalled. In these cases, I get this message on the terminal:
Warning: remote port forwarding failed for listen port 15900
Is there something I can do to make the ssh connection also close when the ProxyJump becomes unavailable ?
Today, the've rebooted the gateway. Unfortunately, David Dai's solution did not work. This is what I saw in the terminal running the tunnel loop:
Timeout, server web.company.com not responding. client_loop: send disconnect: Broken pipe ssh: connect to host employers-Gateway port 22: Connection timed out kex_exchange_identification: Connection closed by remote host Warning: remote port forwarding failed for listen port 15900
Could it be that the work-PC still thought it had the old connection open and refused to open the tunnel a second time (from its perspective) ?
So maybe I was looking on the wrong end. Maybe it's the final target (work-PC) that's unaware of the collapsing tunnel, not the originator (home-PC).
Any thoughts about that ?