Skip to content

Instantly share code, notes, and snippets.

@bryanjhv
Created December 19, 2020 07:28
Show Gist options
  • Save bryanjhv/498943eb6ed46e885bcb92ef83e4439a to your computer and use it in GitHub Desktop.
Save bryanjhv/498943eb6ed46e885bcb92ef83e4439a to your computer and use it in GitHub Desktop.
# Modify them!
LPORT="${LPORT:-22}"
RPORT="${RPORT:-8022}"
SSH="${SSH:-"ssh -C -q -N -f"}"
TARGET="${TARGET:-"theuser@remotehost"}"
is_pi() {
# You can replace this check to your needs.
# Just make sure you return something true.
test -f /etc/rpi-issue -a -r /etc/rpi-issue
}
if is_pi
then
echo "Forwarding L$LPORT to R$RPORT"
$SSH -R "$RPORT:localhost:$LPORT" "$TARGET"
else
echo "Forwarding R$RPORT to L$RPORT"
$SSH -L "$RPORT:localhost:$RPORT" "$TARGET"
fi
echo "Connect to RPi using this command:"
echo " ssh pi@localhost -p $RPORT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment