Remote pair programming using GNU Screen

Original author: Dalibor Nasevic
  • Transfer
The translation of this article can serve as a good step-by-step instruction for those who regularly use pair programming, or at least share code, and are familiar with and ready to use text editors that work in text mode (Emacs, vi, etc.). The article gives a lot of interesting links, I advise you to run a look at them, and the first comment contains a link to a similar experience, but with a cleaner analogue of GNU Screen - tmux .

We have two distributed teams at Siyelo , one in Cape Town, the second in Skopje. We have to figure out how to do remote pair programming between offices. There are many possibilities (excellent generalizing post here ).
Previously, we constantly used Skype to split the screen, but we had the following problems:

- there is no control over the screen of another user ( strange, I have such an opportunity, perhaps with the help of some kind of plug-in )
- it is impossible to split the screen at the same time and use video conferencing ( for more details, see the note on the link given a few lines above )
- network bandwidth can sometimes be a problem
- this is not a tool for pair programming


We recently experimented with Google+ Hangouts, and although we found it had the same flaws, we preferred it for audio and video conferencing. But what we really need from a pair programming tool is co-editing code in real time.

Solution: screen . Screen has many useful usage scenarios, but in this article we will focus on the following two:

- read-only: convenient as splitting the screen on one side without the possibility of intervention by the other
- allowing: convenient for joint programming

Below is how to run both scenarios. Note: the disadvantage of such tools as screen is that all participants need to be able to use the editor that runs in the terminal. Fortunately, we all love vim.

First of all, we need to install an SSH server, since all communications will go through a secure channel:

sudo apt-get install openssh-server

For the first scenario, we will need to add a guest account on the receiving side. For security reasons, we will create it using rbash ( restricting bash), which will be used by the programmer on the remote side in order to connect to our machine.

sudo useradd -s / bin / rbash guest
sudo passwd guest
sudo mkdir / home / guest

Next, we need to set the profile of the guest account. Add the following to /home/guest/.profile:

trap "" 2 3 19 # prevent the user from entering the shell
clear
echo “Welcome to the pair programming session”
echo -n “Press Enter to continue” && read
screen -x dalibor / pairprog
exit

Here, as you can see, "screen -x dalibor / pairprog" will automatically connect the guest to the session with the code "pairprog", which is started by the user "dalibor".

Next, we need to install screen on the receiving side (just in case, if it is not already there):

sudo apt-get install screen

For security reasons, screen is set by default so that system users cannot connect to other users' sessions (error message "Must run suid root for multiuser support."). To allow other users to connect you need to run the following (it is necessary to correct the path to the screen):

sudo the chmod + s / usr / bin directory / screen
sudo the chmod 755 / var / run / screen

Note. perev. Perhaps it would be enough to add both users to a group, say, pairs, and make chgrp on this group.

Next, add the following lines to the ~ / .screenrc configuration file:

hardstatus on
hardstatus alwayslastline
startup_message off
termcapinfo xterm ti @: te @
hardstatus string "% {= kG}% - w% {. rW}% n% t% {-}% + w% =% {.. G}% H% {.. Y}% m /% d% C % a "
screen -t bash1 1

# multiuser setup
multiuser on
aclchg guest -wx" # ,? "
aclchg guest + x “colon, wall, detach”

The most important thing here is “multiuser on”, which allows several users to simultaneously connect to the session and “aclchg”, which removes all restrictions on recording and execution for all windows (#) and commands ( ?) guest user. Having configured it this way, the receiving party can do anything, and the guest can only watch, or write messages usingwall "hello!".

In the end, the screen session is started by the receiving party:

screen -S pairprog The

guest logs in via SSH to the receiving machine:

ssh guest @ host

Now you can work together with one terminal. A little more about screen commands here .

If we trust the guest user, you can add him rights using the "acladd" command.

multiuser on
acladd guest

In this case, the guest user can join the session (already logging in via SSH) with the following command:

screen -x host / pairprog

For more information on screen commands, see the command reference . Basic commands:

Ctrl-a d # disconnect from screen screen
Ctrl-a Ctrl-a # switch back and forth between screens
screen -r # reconnect to the screen screen

If suddenly you are not going to read the links, below are interesting things from there.

During the sessions, I want to not only hear, but also see the second participant, otherwise you will lose body language.

There is a more humane analogue of GNU Screen - tmux, which came from NetBSD, with a more thoughtful architecture, with more readable and supported code. Everything else, it has both horizontal and vertical window separation, available without any patches. Here's a quick note on pair programming with tmux and vim.

Also popular now: