Skip to content

Instantly share code, notes, and snippets.

@vaelen
Created August 12, 2016 16:45
Show Gist options
  • Select an option

  • Save vaelen/0dd849f2224d7be869815f263d20911b to your computer and use it in GitHub Desktop.

Select an option

Save vaelen/0dd849f2224d7be869815f263d20911b to your computer and use it in GitHub Desktop.
A bash script for routing connections through a gateway machine. You can create symlinks to this script named the same thing as the remote hostnames.
#!/bin/bash
GW="vagrant@localhost"
GW_PORT=2222
GW_NAME="gw"
HOST=${0##*/}
if [ "${HOST}" == "connect.sh" ]
then
HOST=$1
fi
if [ -z "${HOST}" ]
then
echo "Please provide a host to connect to."
exit 1
elif [ "${HOST}" == "${GW_NAME}" ]
then
ssh -A -t -X -p ${GW_PORT} ${GW}
else
ssh -A -t -X -p ${GW_PORT} ${GW} "/usr/bin/ssh -t -X -A ${HOST}"
fi
@vaelen
Copy link
Copy Markdown
Author

vaelen commented Aug 12, 2016

You can create symlinks to this script named the same thing as the remote hostnames that you want to connect to.

$ ln -s connect.sh node2
$ ./node2
Last login: Fri Aug 12 16:45:09 2016 from 172.28.128.1
[vagrant@node2 ~]$ exit
logout
Connection to node2 closed.
Connection to localhost closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment