At Kabisa we are big fans of pair programming. Unfortunately, we can’t always sit fysically together when doing so. In this case, we do remote pair programming using TMux and SSH.
To attach to the same session, the host connects to his own machine using SSH, and the client does as well. We use public keys for this purpose. But since I don’t want anyone in my own user account directly, I create a user with standard priviledges, called ‘pairing’.
To make a long story a bit shorter:
Host:
- ssh pairing@localhost
- start TMux, that sudo’s to account of host, kicks of another TMux as host
- bootstrap dev environment
Client:
- ssh paigin@pairinghost
- tmux attach
Here are the instructions to build such an environment:
Setup remote pair programming
This guide will help you setup a pair-programming environment using Tmux, and ssh.
We are going to use a tmux session on your own account (since you already have your project environment there) So the setup will be:
- You and your pair will login to your own machine using SSH
- One of you will kick off a Tmux session that is totally stripped of visual elements that, in turn will kick-off a tmux session as the user with the project environment. The reason to do this is if the tmux is strictly running as the paired user, you need to switch user for every window or pane created.
- In the nested tmux session, the environment will be bootstrapped using
teamocil. Teamocil is used to setup windows, session name and kick of commands for various panes. - The teamocil config file will be made dynamic so that its setup file can be checked in into the project repository so that every team member can use the same environment setup.
Initial setup
- install tmux:
brew install tmux - setup a nice tmux config: eg. TMux config of Matthijs Groen (this config assumes the use of a Powerline patched font)
- setup a user account, eg. ‘Pairing’. Give this user standard permissions.
- setup remote login for this user:
System preferences -> Sharing -> Remote login - setup public key login for this user on your own machine, so that you can use
ssh pairing@localhostwithout using a password.- sudo cp ~/Downloads/id_dsa.pub /Users/pairing/
- su pairing
- cd ~
- mkdir .ssh
- chmod 700 .ssh
- cat id_dsa.pub >> .ssh/authorized_keys
- rm id_dsa.pub
Project setup
Create a ./start-.sh file in the home folder of the ‘pairing’ user:
#!/bin/bash tmux -f .tmux-bare.conf new "sudo -u -i tmux"
the
.tmux-bare.confhas the following contents (also in home of ‘pairing’):## keybindings set -g remain-on-exit off set -g default-terminal "screen-256color" set -g status off
chmod +x ./start-.sh
setup a
sudorule that the pair user may run tmux as your own usersudo visudosetup in this file the rule that the user pairing may run tmux as another user:
pairing ALL=() NOPASSWD: /bin/zsh -c tmux
setup in your own () alias file the following rules: (eg.
.zshrc)# Projects export _ROOT='~/path/to/project' alias tmux-="tmux rename-window 'Zoom' && tmux set-option default-path ${_ROOT} && teamocil --layout ${_ROOT}/tools/teamocil.yml"install teamocil for your own user globally:
sudo gem install teamocil
Using Tmux
Starting session
ssh pairing@localhost `./start-.sh`
in the first tab: tmux-
Joining session
ssh pairing@IP tmux attach
Leaving session
Ctrl+b d (detach-session) *
Killing session
Ctrl+a q (kill-session)
* Ctr+a is the TMux binding of your user TMux. The Pairing TMux will also automatically close when the session of the user TMux ends
* Ctr+b is the TMux binding of your pairing TMux.
Geen opmerkingen:
Een reactie posten