I have looked at various questions but none seems to work...
I have a remote Pi that for various reasons tends to lose power occasionally and then boot back up. I don't have physical access to this thing very often so I set up an ssh tunnel to access it remotely. I need this tunnel to start when the Pi reboots so that I can always have access, even if the power goes in and out.
I have the following script
create_tunnel.sh running in a cronjob (user and hostname removed obviously):
/usr/bin/ssh -i /home/user/.ssh/id_rsa -N -R 4445:localhost:22 user@hostname & if [[ $? -eq 0 ]]; then echo "Tunnel to host created successfully" else echo "An error occurred creating a tunnel to host. RC was $?" fi
And here is the crontab:
@reboot /usr/local/sbin/create_tunnel.sh > /usr/local/sbin/tunnel.log
When I reboot manually, I can see in
tunnel.log that the job ran:
Tue 4 Apr 13:34:27 EDT 2017 Tunnel to host created successfully
But the tunnel does not exist. And when I go to run the command manually, after the Pi has booted, the tunnel comes up fine and I can connect to it without any hassle. What's going on? Is the tunnel getting created and then later destroyed somehow?