📜 ⬆️ ⬇️

Remote programming pair using GNU Screen

Translation of this article can serve as a good step-by-step instruction for those who regularly use pair programming, or at least a joint viewing of the code, while being familiar and ready to use text editors working in text mode (Emacs, vi, etc.). The article contains many interesting links, I advise you to run over them with your eyes, and the first comment contains a link to a similar experience, but with a cleaner analogue of the GNU Screen - tmux .

We have two distributed teams in 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 (an 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 ( strangely, I have such an opportunity, perhaps with the help of some kind of plug-in )
- it is impossible to simultaneously share the screen and use video conferencing ( about why it is needed in more detail is in the note on the link given several 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 the same flaws in it, we preferred it for audio and video conferencing. But what we really need from the 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: conveniently as a split screen by one side without the possibility of interference by the other
- allowing: convenient for joint programming

Below is how to run both scripts. Note: the lack of such intruments as screen is that all participants need to be able to use an 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 ( limiting 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 a guest account profile. Add the following to /home/guest/.profile:

trap "" 2 3 19 # prevent the user from breaking into 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 it is not there yet):

sudo apt-get install screen

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

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

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

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

hardstatus on
alwayslastline hardstatus
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 (?) Of the guest user. By configuring it this way, the receiving party can do anything, and the guest can only watch, or write messages using <ca> wall “hello!”.

In the end, the screen session is started by the host:

screen -S pairprog

Guest logs in via SSH on the host machine:

ssh guest @ host

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

If we trust the guest user, you can add rights to it with the help of the “acladd” command.

multiuser on
acladd guest

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

screen -x host / pairprog

More information about screen commands can be found in the command directory . Basic commands:

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

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

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

There is also a more humane analogue of GNU Screen - tmux, which came from NetBSD, with a more elaborate architecture, with more readable and supported code. Everything else, it has both horizontal and vertical separation of windows, available without any patches. Here is a brief note about pairing with tmux and vim.

Source: https://habr.com/ru/post/132354/


All Articles