Skip to content

Commit

Permalink
ssh: add "rssh" for reverse-SSH command
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbernat committed Dec 27, 2012
1 parent 59756f7 commit b49300a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions rc/ssh.zsh
@@ -1,7 +1,6 @@
# -*- sh -*-

ssh() {
_vbe_title "$@"
_vbe_ssh() {
# TERM is one of the variables that is usually allowed to be
# transmitted to the remote session. The remote host should have
# the appropriate termcap or terminfo file to handle the TERM you
Expand Down Expand Up @@ -40,3 +39,28 @@ ssh() {
;;
esac
}

ssh() {
_vbe_title "$@"
_vbe_ssh "$@"
}

# The following command implements a reverse SSH connection. This is
# to connect to hosts behind a firewall, which can connect to your
# machine but you cannot connect directly. The idea is that they issue
# a TCP connection that you will use as a tunnel to access their SSH
# port.
#
# I am using this to connect to VM using user-mode network (QEMU, KVM,
# UML, ...).
rssh() {
# We should probe for a free port, but is it easy?
local port
port=$((21422 + $RANDOM % 1000))

print "On remote host, use \`socat TCP:10.0.2.2:$port TCP:127.0.0.1:22\` to allow SSH access... "
_vbe_title "$@"
_vbe_ssh -o \
ProxyCommand="socat TCP-LISTEN:$port,bind=127.0.0.1,reuseaddr STDIO" \
"$@"
}

0 comments on commit b49300a

Please sign in to comment.