Skip to content

Instantly share code, notes, and snippets.

@jamesandariese
Created March 7, 2015 04:54
Show Gist options
  • Save jamesandariese/c9a099d54fd1ee8db718 to your computer and use it in GitHub Desktop.
Save jamesandariese/c9a099d54fd1ee8db718 to your computer and use it in GitHub Desktop.
Quick rockin' ssh tunnel!
You have a VPN to work.
You have a gateway host you're required to ssh through.
You have a mac.
You want SSHing to be fast, if possible.
10.0.0.10 is a fill in for the bastion host.
My name is James. Your name probably isn't.
10.11.12.13 is a fill in for my desktop.
If you're not connected to the VPN, it will just try and connect directly.
The ControlPersist stuff is pretty important to make things nice and fast.
!/bin/bash
# change IPSec and WORK-VPN to match your VPN settings.
# WORK-VPN is the name of the interface in your config
# IPSec or PPTP or whatever. You can also use the UUID.
if scutil --nc list|grep IPSec|grep -F '"WORK-VPN"'|grep -q Connected ;then
# The VPN is online. Let's connect through ssh-gateway!
ssh -q -oHostKeyAlias=ssh-gateway -W $1:$2 -l james 10.0.0.10
else
ssh -q -oHostKeyAlias=james-desktop -W $1:$2 -l james 10.11.12.13
fi
Host *
ControlPath ~/.ssh/controlmasters/%r@%h:%p
ControlMaster auto
ControlPersist 0
Host james2
ProxyCommand ~/bin/ssh-to-work %h %p
User james
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment