What I want is like following:
- I could setup a ssh tunnel at background on a Linux machine(Actually, I'd like to setup it in my .bashrc)
- I could run process using this tunnel as any user on this machine at any time, only if the ssh tunnel process is active.
- When I quit from the terminal/session, the ssh tunnel should also quit as well.
I know I could establish a background ssh tunnel in Linux as following:
ssh -Nf -L 8000:22.214.171.124:8000 email@example.com
While at the time I exit from this terminal/session, this ssh tunnel would still run at background.
How to make it also quit automitically?
For my case, I need set a SSH tunnel almost every time I login my server(in order to bypass stupid company firewall). While on another hand, I prefer leaving nothing after my logout.
This http://www.g-loaded.eu/2006/11/24/auto-closing-ssh-tunnels/ doesn't meet my requirement. Because it requires me to launch my process right after the ssh tunnel process, and if my first task with ssh tunnel finished, I need setup the ssh tunnel again for a second task. On the other hand, if I set a long sleep time, then the ssh tunnel will not quit with my terminal.
Maybe editing .bash_logout is possible? I hope there's a clever solution with lest scripts involved.