Linux remote pair programming with tmux

2017-01-10

Pair programming is a well-known technique to avoid bugs by doubling the amount of eyeballs on a piece of code, to increase the quality of code by doubling the amount of brains thinking about a problem, and to make programming more social and collaborative.

Its use is high and increasing in the industry, especially pairing a senior developer with a junior developer to help the junior understand the tools, the code and the workflow of the team.

It's possible to do pair programming in Linux when working remotely by using terminal multiplexers (if you are using a text-based editor like vim or emacs ). The two most famous terminal multiplexers are screen and tmux , and I'm going to show you how to do pair programming using tmux .

Short introduction

Before we start, a short introduction to the concepts so the tutorial will make sense: tmux uses a socket to communicate all of its sessions. This socket can simply be a file (I'm going to use a file here) and anyone with read and write permissions to this socket can participate in the session.

Tutorial

Step 1: Create the needed users.

1
2
# adduser user1
# adduser user2

Step 2: Create a common group for everyone.

This group is going to have all users allowed to participate in the session and the socket will be assigned to it.

1
2
# groupadd pair
# usermod -a -G pair user1 user2

Step 3: Create the session on the socket.

1
2
# apt-get -y install tmux
$ tmux -S /tmp/pair.sock new -s pair

It is advisable to create the socket inside /tmp to avoid cluttering the system and data leakage.

Step 4: Grant read and write access to the socket.

1
$ chgrp pair /tmp/pair.sock

Step 5: Tell people to join the session.

1
$ tmux -S /tmp/pair.sock attach -t pair

That's it. Whatever anyone sees in their terminal, everyone else will see the same. Enjoy!