Skip to content

Instantly share code, notes, and snippets.

@wido
Created October 2, 2019 09:28
Show Gist options
  • Save wido/e5e9361e699c3eaaee5ae0d824882f54 to your computer and use it in GitHub Desktop.
Save wido/e5e9361e699c3eaaee5ae0d824882f54 to your computer and use it in GitHub Desktop.
Reverse SSH tunnel
#!/bin/bash
## To use: `ssh -p 33333 <name>@localhost` from server
server="[email protected]"
port=$(cut -c 13-17 < /var/etc/vin)
localHost="localhost"
if [ "$server" == "[email protected]" ]; then
echo "Script not yet setup, quitting"
exit 1
fi
while : ; do
RET=`ps ax | grep "$localHost:22" | grep -v "grep"`
if [ "$RET" = "" ];then
ssh -p 22 -N -T -R $port:127.0.0.1:22 -o ServerAliveInterval=3 -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes $server
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment