autossh -- keeping ssh port forwards alive
April 12th, 2007
For a project I recently needed a way to access a server behind a NAT from another server on the internet. This is no problem for ssh, but keeping the forward alive is not that easy, especially since the server behind the NAT is only on a dial-in account which means it’s public IP changes every 24h and all connections get dropped when this happens.
I tried writing a small shell script for respawning ssh when it exited but it really did not work as reliably as I expected.
Luckily someone recently mentioned a tool which was written exactly for this purpose: autossh
Now I’m spawning it like that on the server behind the nat:
autossh -M0 -o ServerAliveCountMax=2 -o ServerAliveInterval=15 \
-o ExitOnForwardFailure=yes myserver -N -R5001:127.0.0.1:2800
And it’s even in portage :)
Sorry, comments are closed for this article.