Skip to content

Instantly share code, notes, and snippets.

@kmeister2000
Forked from marksim/README.md
Last active December 19, 2015 09:49
Show Gist options
  • Save kmeister2000/5935441 to your computer and use it in GitHub Desktop.
Save kmeister2000/5935441 to your computer and use it in GitHub Desktop.

My script for pair sessions on my box.

What it does

  • downloads the appropriate ssh keys from github
  • punches a hole in my firewall (see Note #2)
  • copies the appropriate 'ssh pair@your-external-ip' command to your clipboard (see Note #1)
  • sets up the tmux session
  • cleans up the session, the keys and the firewall after it's done

How to use

If you want your pair to auto-connect to your tmux session, then just copy the following to ~pair/.bash_profile

tmux -S /tmp/pairing attach -t pairing
exit

Then you type:

pair-session marksim

After that, just hit paste into your pair's chat window and voila, they ssh in and are automatically connected via tmux.

Issues

  1. If you are running linux, you can easily alias pbcopy and pbpaste like so: http://whereswalden.com/2009/10/23/pbcopy-and-pbpaste-for-linux/
  2. This is specific to my router, but you might be able replace the firewall calls to something that makes sense for you.
#!/bin/sh
# *************************** SETUP ****************************
# Find the LAN IP, the External IP, and the pair users's group
INTERFACE=$(netstat -rn -f inet | grep default | awk '{print $6}')
LAN_IP=$(ipconfig getifaddr $INTERFACE)
EXTERNAL_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
EXTERNAL_PORT=222
GROUP=$(id -g pair)
# Download the public keys to the pair user
sudo bash -c "curl https://github.com/$1.keys 2>/dev/null >> ~pair/.ssh/authorized_keys"
sudo chown pair:$GROUP ~pair/.ssh/authorized_keys
# Punch a hole in the firewall
curl "http://192.168.0.1/scvrtsrv.cmd?action=add&srvName=aDv_PoRt_FoRwArDiNg&srvAddr=$LAN_IP&eStart=22,&eEnd=22,&proto=1,&iStart=22,&iEnd=22,&srvWanAddr=0.0.0.0&needthankyou=advancedsetup_advancedportforwarding.html" 2>/dev/null >/dev/null
# Copy the ssh command to the clipboard - OS X specific
echo "ssh -p $EXTERNAL_PORT pair@$EXTERNAL_IP" | pbcopy
# ************************** PAIRNG ****************************
tmux -S /tmp/pairing new -ds pairing && chgrp $GROUP /tmp/pairing && tmux -S /tmp/pairing attach -t pairing
# ************************** CLEANUP ***************************
# Cleanup keys
sudo rm -f ~pair/.ssh/authorized_keys
# Patch hole in the firewall
curl "http://192.168.0.1/scvrtsrv.cmd?action=remove_port_forwarding&rmLst=$LAN_IP|22|22|TCP|22|22|0.0.0.0&needthankyou=advancedsetup_advancedportforwarding.html" 2>/dev/null >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment