Created
October 12, 2010 05:57
-
-
Save rupa/621729 to your computer and use it in GitHub Desktop.
ssh/scp through NAT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" $* | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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