Coder Social home page Coder Social logo

autossh-tunnel's Introduction

autossh-tunnel

Setup and keep alive ssh tunnels to remote sites using autossh, screen.

Requirements

  • bash
  • autossh
  • screen
  • awk (optional)
  • sed (optional)

How it works

Configure the sites you want to tunnel to in ~/.ssh/config: Host declarations prefixed with 'autossh-' are detected as candidates for tunnel sites, for example:

Host autossh-HOSTNAME
Hostname HOSTNAME
User USER
RemoteForward 8022 localhost:22
IdentityFile ~/.ssh/autossh-id_rsa

ssh-keygen.sh: this is a helper script to generate an SSH key with empty passphrase. Beware, normally this is considered a dangerous thing to do. We sacrifice some security in favor of convenience, so that you can easily start ssh tunnels from cron, without having to reenter a passphrase after every reboot.

To make this less insecure, the public key will be configured on the remote site with these very restrictive ssh key authorization options:

command="/bin/false",no-agent-forwarding,no-X11-forwarding,no-pty

ssh-copy-id.sh: this is a helper script to install the dedicated SSH key in ~/.ssh/authorized_keys on each of the detected tunnel sites.

setup.sh: helper script to walk you through the setup steps or print the details of the detected setup:

  • Print the details of the detected setup, such as:

    • SSH key that will be used with autossh
    • Detected tunnel sites in ~/.ssh/config
    • Confirmed tunnel sites (accepting the SSH key)
  • Print the steps to complete the configuration.

  • Print tips how to test the configuration.

autossh.sh: wrapper script to run autossh for each detected site in an independent screen session. It reuses an existing session or else it creates a new one.

crontab.sh: helper script to add a line like this in crontab to periodically run autossh.sh:

0 * * * * $PWD/autossh.sh

How to install

Simply run ./setup.sh and follow the steps. This script does not do anything. It only tells you the configuration it detected and gives you the steps you need to follow to complete the configuration.

How to uninstall

  • Remove any cron jobs running autossh.sh
  • ./stop.sh to stop any running autossh and screen instances
  • Login to each tunnel site and manually remove the script's SSH key from ~/.ssh/authorized_keys

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.