Tip #154 Port forwarding that automatically disconnects
If you want to tunnel a long-lived connection over SSH such that the tunnel goes away when the application disconnects, try something like the following example:ssh -f -q -L 5900:localhost:5900 user@remotehost.com sleep 60
By executing "sleep 60" remotely, the tunnel stays alive for at least 60 seconds, and assuming your application has connected by then, the tunnel will continue to stay alive until the application disconnects.
The options given above are perfect for executing this command from a script; it is quiet (-q) and goes to background after prompting for a password (-f). This particular example forwards the VNC protocol so that when your VNC client connects to localhost, it connects securely to remotehost.com over the tunnel.
- TAGS:
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs