Instantly share code, notes, and snippets.

@bf4 / forked from marksim/
Created Jan 8, 2014

What would you like to do?

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.


  1. If you are running linux, you can easily alias pbcopy and pbpaste like so:
if [[ $# -eq 0 ]] ; then
echo "Usage: $0 [tmux-session-name] github-username [github-user-name [...]]"
exit 0
# *************************** 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
GROUP=$(id -g pair)
if [ -e /tmp/$1 ]; then
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 "$@"
sudo bash -c "echo '$SSH_KEYS_STRING' >> ~pair/.ssh/authorized_keys"
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

This comment has been minimized.


bf4 commented Jan 16, 2014


This comment has been minimized.


bf4 commented Feb 23, 2014

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