Skip to content

Instantly share code, notes, and snippets.

@xopr
Created April 11, 2018 07:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xopr/f252219c2fab68a85086d95baf5b0148 to your computer and use it in GitHub Desktop.
Save xopr/f252219c2fab68a85086d95baf5b0148 to your computer and use it in GitHub Desktop.
Use autossh and screen to create a tunnel back to the local host publicly available on 'remote'
#!/bin/bash
echo Setting up remote tunnel in screen session
screen -dmS tunnel autossh -N -R *:2222:localhost:22 -i .ssh/cypher tunnel@remote -p22
@stuiterveer
Copy link

stuiterveer commented Apr 11, 2018

Check if screen session for tunnel already exists before executing:

if ! screen -list | grep -q "tunnel"; then
    echo Setting up remote tunnel in screen session
    screen -dmS tunnel autossh -N -R *:2222:localhost:22 -i .ssh/cypher tunnel@remote -p22
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment