Skip to content

Instantly share code, notes, and snippets.

@v1k0d3n
Last active April 16, 2023 10:31
Show Gist options
  • Save v1k0d3n/c82a07547e2050e4ad1176708c9fa5c6 to your computer and use it in GitHub Desktop.
Save v1k0d3n/c82a07547e2050e4ad1176708c9fa5c6 to your computer and use it in GitHub Desktop.

Overview

For anyone doing remote lab work or demonstrations which include jump servers, this is your new best friend.

Installation

In MacOS, you can simply use brew to install sshuttle:

brew install sshuttle

Or on any other system, you can simply use python-pip3:

pip3 install -U sshuttle

Setup

Add the following directory: mkdir -p $HOME/.sshuttle/pid/

Then add the following to your ~/.bashrc or ~/.zshrc file:

export REMOTE_TUN_IP="172.25.186.2"
export REMOTE_TUN_NETS="172.25.179.0/24 172.25.180.0/24 172.25.181.0/24"
export REMOTE_SESSION_NAME="sshuttle_session"

alias sshtup='sudo sshuttle --daemon --pidfile=$HOME/.sshuttle/pid/'"$REMOTE_SESSION_NAME"'.pid --dns -vr $USERNAME@'"$REMOTE_TUN_IP":22' '"$REMOTE_TUN_NETS"' && echo "Connected to $REMOTE_TUN_IP"'
alias sshtdown='[[ -f $HOME/.sshuttle/pid/'"$REMOTE_SESSION_NAME"'.pid ]] && sudo kill $(cat $HOME/.sshuttle/pid/'"$REMOTE_SESSION_NAME"'.pid) && echo "Disconnecting from $REMOTE_TUN_IP"'

Next, source your ~/.bashrc or ~/.zshrc file:

source ~/.bashrc
# or
source ~/.zshrc

Usage

Then type the following to connect to the remote host using sshuttle (with networks and remote host DNS):

sshtup

To disconnect, type:

sshtdown

Next

NOTE: Not required, but you could also configure your SSH config file with the following settings for quality of life improvements... In your ~/.ssh/config file, add the following:

Host *
  ConnectTimeout 5
  ControlMaster auto
  ControlPath ~/.ssh/active-%r@%h.%p
  ServerAliveCountMax 120
  ServerAliveInterval 60
  TCPKeepAlive no
  ForwardX11Trusted yes
  AddKeysToAgent yes
  StrictHostKeyChecking no
  UserKnownHostsFile=/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment