, , ,

Unix – Permanent SSH Tunnel – The easy way 🙂

OK, this is a dead easy instruction of setting up a permanent ssh tunnel through cron
This establishes port forwarding to a remote server.

Command

crontab -e

nc -z localhost  || ssh @ -N -L :: &

Example


* * * * * nc -z localhost 15432 || ssh a@big-bad-server.net -N -L 15432:10.0.80.1:5432 -L 25432:10.0.80.2:5432 &

References

1. Serban Simu, Devenie Corliss, Set up permanent SSH tunnel via cron,
https://support.asperasoft.com/entries/20150692-Set-up-permanent-SSH-tunnel-via-cron