-
on source machine (behind the network), run:
ssh -N -R 2222:localhost:22 YOURUSER@YOURSERVER
-
on YOURSERVER, run:
ssh -l SOURCEUSER -p 2222 localhost
-
If you want to automated it, do something like...
#!/bin/bash
createTunnel() {
/usr/bin/ssh -N -R 2222:localhost:22 serverUser@25.25.25.25
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
-
Get the right permissions
chmod +x create_ssh_tunnel.sh
-
Cron it up!
crontab -e
then jam in:
*/1 * * * * ~/create_ssh_tunnel.sh > tunnel.log 2>&1
Consider adding a sleep $(( ( RANDOM % 10 ) + 1 ))
if you'd like the tunnel re-establishment to be a little less deterministic. Someone could notice an SSH session opening every minute on the minute. Mix it up to look human.