Skip to content

Instantly share code, notes, and snippets.

@markstinson
Forked from relistan/ssh-config
Created January 24, 2013 04:31
Show Gist options
  • Save markstinson/4617651 to your computer and use it in GitHub Desktop.
Save markstinson/4617651 to your computer and use it in GitHub Desktop.
Host *
ForwardAgent yes
ProxyCommand ~/bin/ssh-proxy.sh %h %p username@jump-host
ServerAliveInterval 10
ServerAliveCountMax 600
#!/bin/bash
# ------------------------------------------------------------------------------
# Use SOCKS proxy to proxy SSH through a jump host. This works in
# almost all circumstances and has the advantage of using only one
# SSH tunnel to the jump host for all concurrent ssh tunnels. It
# does not end the open connection to the jump host when the connection
# is closed.
# ------------------------------------------------------------------------------
# Author: Karl Matthias
# Date: Tue 31 Jan 2012
hostname=$1
port=$2
proxy_host=$3
usage() {
die "`basename $0`: [hostname] [port] [proxy_host]"
}
die() {
echo $1 >&2
exit 1
}
test -z $hostname && usage
test -z $port && usage
test -z $proxy_host && usage
nc -z -w 2 $hostname $port > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
nc -w 300000 $hostname $port
else
nc -z -w 2 localhost 9090 > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
ssh -f -N -D9090 $proxy_host
fi
nc -x localhost:9090 $hostname $port
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment