Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to start an ssh tunnel from A to B and have it run despite things like: period network/wifi drops on A and remote server reboot on B. My ssh tunnel starts using upstart script on A with event start on (net-device-up IFACE=eth0)

I've found autossh which is supposed to handle these kinds of things, but had some trouble getting it to work. The upstart executes:

autossh -M 0 -2qTN -o "ServerAliveInterval 30" -o "ServerAliveCountMax 2" -L 5678:somehost:5678 user@B

However when I log into B and kill -9 that tunnel session, autossh just exits with "Connection to B closed by remote host." That's not what I expected autossh to do.

Any advice on how to set this up? Any GUI service monitoring utilities out there that essentially display a green light if a service is up?

Thanks.

share|improve this question
add comment

1 Answer

Maybe a combination with screen will help. For auto reconnect you will need a key authentification too.

I created an alias: alias sshtunnel='TERM=xterm ssh servername -a -x -t /opt/local/bin/screen -xRR -A -e^Zz -U -O -S tunnelToServer' Screen ensures that you terminal session is alive.

Last step is creating a script which checks the host and starts the alias again: $ while :; do while ! ping -c1 -t1 server >/dev/null; do sleep 10; done; sshtunnel; echo Connection to server dropped at $(date); sleep 10; done

That should survive all network drops. You can play around with the sleep times too.

If you call screen -ls you will find your screen session with the name "tunnelToServer".

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.