0

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

7
  • XY problem? What do you mean by "the tunnel sometimes goes down"? 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. Investigate ExitOnForwardFailure=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. Feb 17, 2019 at 0:20
  • @KamilMaciorowski The tunnel doesn't go down as such, but whenever I reboot my device and run autossh again, it seems the server refuses access. What I do to solve this is, run the autossh command as in my question, look at the reply, if it's down, restart my modem and run the autossh command again, and this works. However I have a script doing this every minute running this autossh command which is creating lots of autossh processes. Only one process is needed surely. I'm trying to find a better way to solve this. I don't know what happens exactly every time the autossh command is used. Feb 17, 2019 at 11:03
  • From my answer to the linked question: "Networking on your device somehow drops before 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 run autossh 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. Feb 17, 2019 at 17:52
  • @KamilMaciorowski Thanks for your suggestions. I haven't tried this just yet but I will tomorrow. Yes I am running autossh every minute with cron. I know it's not ideal. If "ExitOnForwardFailure=yes" doesn't work for me, what about if I got the PID of the current running autossh process first before running it again, if the next autossh command connects, then kill the previous previosu. It's extremely hacky but wondering if it would just do. The right solution is to find a better way to determine that my tunnel is working, without having to continuously run autossh (but I haven't found it) Feb 17, 2019 at 18:12
  • @KamilMaciorowski Sorry, I know it's a long discussion here, but you mention "Don't run the next one unless the current one exits". This is my problem. I guess I could check first if there currently exists is a PID for an autossh process, and if not start a new one. However I still need to be sure that if there is an autossh process running , that it is actually establishing communication with the tunnel. That's the problem I have after a reboot, the process runs , but gets stuck and doesn't connect. It's tricky Feb 17, 2019 at 18:22

0

You must log in to answer this question.

Browse other questions tagged .