I'm using autossh to connect to a reverse SSH tunnel. I run it from startup.
However, I was facing problems in that the tunnel sometimes goes down.
I created a script which checks if the tunnel is actually working , and if not do other stuff like restart the modem.
The only way I seem to be able to check if the tunnel is working is by using the autossh command again and checking the reply.
autossh -M 0 -N -q -o ServerAliveInterval=20 -o ServerAliveCountMax=3 [email protected] -i id_rsa -R 13212:localhost:22 -v
I just noticed tho that every time I use this autossh command, it starts a new auto process. There are so many autossh processes running now. This is obviously not good.
There are two questions :
1) Is there a better way to verify if my tunnel is working without using the autossh command again? (I couldn't find another way)
2) The other option I suppose is to kill the processes in my script which are not used and just have the one autossh process. However, How do I find the pid of a process if there are many of them with the name autossh?
Thanks in advance
autossh
should reconnect but if the server doesn't notice the old connection is no more, it won't release the port binding, so the new one won't re-establish the tunnel. InvestigateExitOnForwardFailure=yes
and see this: Disable port forward remotely…. This is not an answer because (1) it doesn't answer the explicit questions, (2) I'm not sure I identified your problem right.ssh
is terminated and there is no way to notify the server this particular SSH connection is no more". For now your problem seems very similar. Do you runautossh
with-f
or&
, or with cron every minute? Don't. Don't run the next one unless the current one exits. Make sure it exits when it should,ExitOnForwardFailure=yes
is the right approach. Have you already tried what my answer says? If it doesn't help, please edit the question and describe exactly what you do/tried and what response you get.