![]() It is based on the "advanced" SSH ControlMaster configuration option, which you best put into your ~/.ssh/config file. I hope I'll be forgiven for not repeating the whole story. ![]() I have found a robust solution at SO, see. This way, no ssh processes are left running in the background. When vncviewer stops using the tunnel, then the ssh client exits too, as it has already accomplished its goal. In other words, the ssh client cannot destroy the tunnel because it would have to kill vncviewer as well. If vncviewer was not used, the ssh client would exit after the 10 sec period, as it would have no more jobs to do, destroying the tunnel at the same time.ĭuring the execution of the sleep command, if another process, vncviewer in this case, starts using that tunnel and keeps it occupied beyond the 10 sec period, then, even if the ssh client finishes its remote job (execution of sleep), it cannot exit because another process occupies the tunnel. The creation of the tunnel is some kind of side-effect, a secondary goal. The difference between this method and the previous one (-N switch), basically, is that in this case the ssh client’s primary goal is not to create the tunnel, but rather to execute the sleep command for 10 seconds. In this case, the ssh client is instructed to fork the ssh session to the background (-f), create the tunnel (-L 25901:127.0.0.1:5901) and execute the sleep command on the remote server for 10 seconds (sleep 10). At the same time, we execute vncviewer exactly as before: ssh -f -L 25901:127.0.0.1:5901 sleep 10 \ We start the ssh session in the background, while executing the sleep command for 10 seconds on the remote machine. How these help in auto-closing the ssh tunnel is explained below. the user can specify for how long it will be executed.it does nothing, so no resources are consumed.This is when sleep can be the most useful command of all! In this particular situation, sleep has two advantages: But, which command should be executed, since we only need to initialize a tunnel? I found the solution here: The best way – Tunnels that auto-closeĪs it has been mentioned previously, instead of using the -f -N switch combination, we can just use -f alone, but also execute a command on the remote machine.
0 Comments
Leave a Reply. |