How to keep an SSH tunnel open in MacOS X
Guest Post
Blog
mgull decided around 00:54 on 2 August 2006 to publish this:
Kitt asked me to post this, so here goes:
ssh_command_no_exit.sh as follows:
ssh -N -l remoteprocess -L13307:127.0.0.1:3306 -R13307:127.0.0.1:3306 -o ServerAliveInterval=240 re.mo.te.ip/Library/LaunchDaemons/ssh_tunneler.plist as follows:
This basically sets up the equivalent of an inittab:respawn on Linux. OnDemand=false indicates that the server should be continuously running. Type inLabel ssh_tunneler ProgramArguments /path/to/ssh_command_no_exit.sh OnDemand Disabled
launchctl load /Library/LaunchDaemons/ssh_tunneler.plistFinally, launchd kills something that fails within 60 seconds 10 times in a row. If our DSL/cable line goes out, this could take longer. So, add the following line to crontab:
#Re-list the ssh_tunneler 10 0 * * 0 launchd load /Library/LaunchDaemons/ssh_tunnelr.plist >> /dev/null &2>1