Skip to content

Instantly share code, notes, and snippets.

@rupa
Created October 12, 2010 05:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rupa/621729 to your computer and use it in GitHub Desktop.
Save rupa/621729 to your computer and use it in GitHub Desktop.
ssh/scp through NAT
# ssh/scp through NAT, as long as $outer has nc
# ssh v5.4+ should allow ssh -oProxyCommand="ssh -W $inner:%p" $outer $*
# hosts could also be defined in .ssh/config:
# Host foo
# hostname inner
# ProxyCommand ssh outer nc -w 1 %h %p
sshh() {
[ "$1" = "-h" ] && {
echo "sshh [opts] outer inner [cmd]"
return
}
[ $2 ] || return
outer=$1
shift
ssh -oProxyCommand="ssh $outer nc -w 1 %h %p" $*
}
sscp() {
[ "$1" = "-h" ] && {
echo "sscp [opts] outer file inner:[file]"
return
}
[ $3 ] || return
outer=$1
shift
scp -oProxyCommand="ssh $outer nc -w 1 %h %p" $*
}
#!/bin/bash
# ssh/scp through NAT, as long as $outer has nc
# ssh v5.4+ should allow ssh -oProxyCommand="ssh -W $inner:%p" $outer $*
# hosts could also be defined in .ssh/config:
# Host foo
# hostname inner
# ProxyCommand ssh outer nc -w 1 %h %p
case $(basename $0) in
sshh) [ $2 ] || exit; action=ssh; usage="sshh [opts] outer inner [cmd]";;
sscp) [ $3 ] || exit; action=scp; usage="sscp [opts] outer file inner:[file]";;
esac
if [ "$1" = "-h" ]; then
echo $usage
else
outer=$1
shift
echo $action -oProxyCommand="ssh $outer nc -w 1 %h %p" $*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment