permanent ssh tunnel chron job
Assume we want to tunnel local port 5000 to the remote computer 10.0.109.1 port 6000.
1. Make sure SSH works - choose a user with an SSH private key such that the ssh command doesn't require a password. Make sure you're not asked for password when connecting. Exit once it connects correctly:
ssh [email protected]
2. Test the tunnel manually. The following command should open a tunnel and background the ssh process:
nc -z localhost 5000 || ssh -N -L 5000:10.0.109.1:6000 [email protected] &
To terminate it type fg and then Ctrl-C.
3. Edit crontab and add the command above. For example to run it every minute as user root:
crontab -u root -e
And add at the end of it:
* * * * * nc -z localhost 5000 || ssh -N -L 5000:10.0.109.1:6000 [email protected] &