Skip to content

Instantly share code, notes, and snippets.

@urish
Created August 16, 2015 15:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save urish/223a193c550ef55d7101 to your computer and use it in GitHub Desktop.
Save urish/223a193c550ef55d7101 to your computer and use it in GitHub Desktop.
Raspberry Pi SSH tunnel
#!/bin/bash
# Based on: http://www.tunnelsup.com/raspberry-pi-phoning-home-using-a-reverse-remote-ssh-tunnel
createTunnel() {
/usr/bin/ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -N -R 0.0.0.0:2222:localhost:22 fwd1@RemoteHost
if [[ $? -eq 0 ]]; then
echo Tunnel to jumpbox created successfully
else
echo An error occurred creating a tunnel to jumpbox. RC was $?
fi
}
/bin/pidof ssh
if [[ $? -ne 0 ]]; then
echo Creating new tunnel connection
createTunnel
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment