Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Mac laptop and would like to have a persistent ssh tunnel so I can always log in from outside the local network. I'm looking for something that will work when the server can't be reached initially (e.g. if I don't have an Internet connection when I boot it), and will automatically start the tunnel when possible.

I've tried putting an @reboot autossh line in my crontab, but I've found that sessions started with autossh disconnect every so often, and autossh quits if the first attempt fails. My current workaround is a small script and a cronjob:

# crontab
/home/blackl/bin/script &!

# script
while true; do ssh -Ngn -R $some_port:localhost:22 $server; sleep 30; done;

Is there a better way to do this, or will I just have to be happy with this for now?

share|improve this question

You must log in to answer this question.

Browse other questions tagged .