Skip to content

Instantly share code, notes, and snippets.

@bf4
Forked from marksim/README.md
Created January 8, 2014 20:33
Show Gist options
  • Save bf4/8324117 to your computer and use it in GitHub Desktop.
Save bf4/8324117 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
  • copies the appropriate 'ssh pair@your-external-ip' command to your clipboard (see Note #1)
  • sets up the tmux session
  • cleans up the session, and the keys after it's done

How to use

First, brew install tmux

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/
#!/bin/sh
if [[ $# -eq 0 ]] ; then
echo "Usage: $0 [tmux-session-name] github-username [github-user-name [...]]"
exit 0
fi
# *************************** 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)
GROUP=$(id -g pair)
if [ -e /tmp/$1 ]; then
SESSION=$1
else
SESSION='pairing'
fi
sudo mkdir -p ~pair/.ssh
sudo chown pair:$GROUP ~pair/.ssh
sudo touch ~pair/.ssh/authorized_keys
# Download the public keys to the pair user
for username in "$@"
do
SSH_KEYS_STRING=$(curl https://github.com/$username.keys)
sudo bash -c "echo '$SSH_KEYS_STRING' >> ~pair/.ssh/authorized_keys"
done
TMUX=$(echo `which tmux` | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')
sudo sed -i -e "s/^/command=\"$TMUX -S \/tmp\/$SESSION attach -t $SESSION\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding /" ~pair/.ssh/authorized_keys
sudo chown pair:$GROUP ~pair/.ssh/authorized_keys
# Copy the ssh command to the clipboard - OS X specific
echo "ssh pair@$EXTERNAL_IP" | pbcopy
sudo -k
# ************************** PAIRNG ****************************
function setup_session {
tmux -S /tmp/$SESSION new -ds $SESSION && chgrp $GROUP /tmp/$SESSION && tmux -S /tmp/$SESSION attach -t $SESSION
}
tmux -S /tmp/$SESSION attach -t $SESSION || setup_session
# ************************** CLEANUP ***************************
# Cleanup keys
sudo rm -f ~pair/.ssh/authorized_keys
sudo -k
@bf4
Copy link
Author

bf4 commented Jan 16, 2014

@bf4
Copy link
Author

bf4 commented Feb 23, 2014

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