May 29, 2016 by Daniel P. Clark

How to Build the Ultimate Remote Pair Programming Environment

There are a handful of desktop sharing apps out there and there are plenty of shell/editor sharing setups.  But the biggest problem with these is you are opening up your own personal computer to not only the person(s) you’re connecting with, but also the potentially vulnerable or malicious technology you choose to use.  A proper peering environment will be sandboxed in to prevent any possible direct attacks to your operating system.  Security should never be an afterthought.

Getting Started

You can set this up on any major operating system.  For this I recommend a moderately nice computer with at least 4 Gigs of RAM (I prefer 8), and about 10 Gigs of hard drive space depending on your choice of Linux distro.  You’ll need to install a Virtual Machine; I recommend VirtualBox which is free to use.  Once this is installed you’ll need to download a Linux OS to install.  Choose a 32-bit lightweight desktop for the best experience. Ubuntu Mate is a good choice.  Remember get the 32-bit i386, or i586 version, not the 64-bit one.

Create a New Virtual Machine

In VirtualBox click New, give it a name “PairProgramming” and set the OS to Linux and Ubuntu (32-bit) and click Next.  For memory size enter 2048 Mb if you have 4 Gigs of memory in your computer, but if you have more than that go ahead and set the memory to 3072 Mb and click Next.  Ubuntu Mate is going to want a little more than 8 Gigs of space to install so here we’ll select Create a virtual hard disk now and click Create.  Select VDI and click Next.  Dynamically allocated and Next. Set the size to 9.0 Gigs for Ubuntu Mate and click Create.

Install the Virtual Machine

Now you’ll see a virtual machine named PairProgramming in your VirtualBox dashboard.  Right click on it and go to settings.  Click on Storage and then click on the CD icon that says Empty and then all the way on the right click the CD icon drop down menu and select Choose Virtual Optical Disk File…  then select the ISO image of the Linux installation file you downloaded (in my case it’s named ubuntu-mate-16.04-desktop-i386.iso) and click OK.  Now you’re ready to start the install so click the green Start arrow to boot up your virtual machine and go through your Linux distros install process.

Install Ubuntu Mate

The first thing that shows up in install is the language choice.  With English selected hit the Enter key.  Go down to Install Ubuntu MATE and hit Enter.  Now the desktop installation screen is open with yet another language selection screen; with English selected hit the Continue button.  Check the box that says Download updates while installing Ubuntu MATE and click Continue.  Now for the Installation type choose Something else (we’re not going to create a swap partition) and click Continue.  Click the New Partition Table… button, when the warning pops up click Continue, double click on free space and in the popup box the only thing you need to enter is the Mount point: which you will set to a forward slash / and click OK.  Now click Install Now.  When the warning window about swap space pops up just click Continue, and with the confirmation popup click Continue.

Select your timezone and press the Continue button.  For the Keyboard layout leave it as Keyboard(US) and press Continue.  The Who are you? user creation will be the admin user for changing and installing things on this Linux distro.  Create your own account and use a good password (you will not share this for pairing it is for admin only).  Once you’ve entered the information for your new account press Continue.  Now everything will install.  You will have enough time to make a coffee and smell the roses here.  Once the install is done click on Restart Now.  When the computer has rebooted login to your account and when the Software Updater popup comes up go ahead and click Install Now (the install password will be the same password as the one you used to create the admin account).

Setup Remote Access

The two core things we’ll need for setting up remote access for desktop sharing is xrdp and ngrok.  After all installation updates are done open up a terminal (right-click and go to Open in Terminal will work) and install xrdp

sudo apt-get -y install xrdp

Next, change the encryption level to high from the default low:

sudo nano /etc/xrdp/xrdp.ini
encrypt_level=high

And change the [xrdp1] section in the same file to:

[xrdp1]
name=pair-programming
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=5912

CTRLO and CTRLX to save and exit. Next, allow just RDP through the local firewall:

sudo ufw allow 3389/tcp

Restart xrdp and you should be able to connect:

sudo /etc/init.d/xrdp restart

Now to install ngrok got to https://ngrok.com/download and in Step 1: Download ngrok click on 32-bit platforms then click the Download button for Linux 32-bit and Save File from the popup window.  Then in your terminal type:

cd ~/Downloads
sudo unzip ngrok-stable-linux-386.zip -d /usr/bin

Now you need to add in your ngrok authentication so go to ngrok.com and sign up, then log in on the site and click the Auth tab.  There they will have a command for you to enter into your terminal to add access.

cd ~
ngrok authtoken A_REALLY_LONG_TOKEN_PROVIDED_FROM_SITE

Make sure you drop the leading dot slash ./ the site has for the command. Now you’re able to open an external port for remote access with the following:

ngrok tcp 3389

This will launch ngroks port forwarding application and show you an address you can have anyone connect with which will look like: tcp://0.tcp.ngrok.io:00000 .  In any RDP client you can now just enter the 0.tcp.ngrok.io:00000 part and connect.  No other information is needed to connect (although in my Remmina Remote Desktop Client I have to set the color settings to True Color for it to work).  Once connected there will be a login prompt.

TIP: When you run the ngrok command; the information of address and port is available at ngrok.io under your dashboard.  You can run it at home, leave, and check and use it remotely yourself.  If your internet is prone to disconnecting you may want to write a script that will restart your ngrok command after it’s been disconnected.  With the website you’ll have up to date connection info.

Since we don’t want to give out the admin account with install privileges we need to create another user account.  Click the top System menu then Administration then Users and Groups.  In User Settings click the Add button, enter your admin password to proceed, in the Create New User dialog enter a username: Like pp, then hit OK.  Under enter password by hand put in a password you plan to share for your pair programming sessions: like pairpass and hit OK.  If prompted for the admin password go ahead and enter and submit that.

Now you’re ready to connect to people to a shared programming session.  Both you and your partner need to use a RDP client to connect (even though you yourself are at the same computer).  When you both login with the same account (example: user: pp, password: pairpass) you will both be logged into the same desktop and each have your own mouse cursor and keyboard input.  When doing this on your host operating system, or mobile device, you should open up a video call with your pairing partner.  This way you can share the secure desktop environment and see and talk to each other at the same time.

Editors

When pair programming you’re going to want to use an editor you’re both okay with. Sublime 2, Vim, and Emacs would be the easiest to setup.  Atom requires a little labor to get it working with remote connections (issue #4360 with hack/fix).  Also you may want to rebuild Vim from source to be compatible with some of your favorite plugins (such as YouCompleteMe with instructions for building Vim from source).

Summary

With this you’ll have a secure remote pairing environment.  This will make for a far more enjoyable pair programming session.  The end setup will have your main computer with 3 open windows: 1) The virtual machine image running the admin account with ngrok executed  2) remote desktop client connected to the pair programming guest account 3) video chat with your partner.

In the iOS app store there is an excellent free client you can use to connect from your iPad Microsoft Remote Desktop.  If you do use your iPad/tablet to connect you can use a bluetooth keyboard and simulate a full PC experience.  You should connect your smaller device first as it will set the size of the desktop automatically.  Then when the PC pair connects it will have a slightly smaller window with the same experience shared.

There’s nothing quite like having the peace of mind of a disposable sandboxed operating system thereby not opening yourself to remote attacks or any of the many malicious software applications out there.  This is quite the fun project and you will likely have a very good experience pairing with others during programming sessions.  Even with this virtual machine to code on I still highly recommend you backup your progress in coding to a remote source such as Github.

As always I hope you found this educational and enjoyable!  Please feel free to comment, share, subscribe to my RSS Feed, and follow me on twitter @6ftdan!

God Bless!
-Daniel P. Clark

Image by herdiephoto via the Creative Commons Attribution 2.0 Generic License

Bonus

If you want to share a pair programming setup with many people but don’t want to copy 9 Gigs of data everywhere or go through this setup every time then you can customize your own Linux install image.  It’s actually a lot easier than you think!  Just follow the instructions to the letter at http://askubuntu.com/a/516879/294210 for customizing the ISO install image and you can make you own custom Linux image.  Once you’ve mounted and extracted the install image you can install all the editors and the remote connection applications and configurations to the image.  And if you want to customize the Vim editor and have it include the plugins without people needed to install/update them after install you can build the vim plugins under /etc/skel/.vim/bundle as the /etc/skel directory will be copied to every new user account that is created.

#linux#pair#pair programming#programming#remote#session#virtual machine

Comments

  1. Øyvind Andreas Eide
    May 29, 2016 - 5:37 pm

    Great writeup. Is there any particular reasoning behind the 32bit choice over 64?

    • Daniel P. Clark
      May 29, 2016 - 6:04 pm

      With 64-bit VirtualBox requires some additional configuration from the computer’s BIOS to enable some VM emulation. This adds more work that people shouldn’t have to do.

      32-bit still allows for 3+ Gigs of RAM usage and runs well as a virtual machine. Basically it’s less trouble to get to work and it’s more compatible to share with others.

      • Øyvind Andreas Eide
        May 29, 2016 - 6:07 pm

        Gotcha. Thanks

  2. Øyvind Andreas Eide
    May 29, 2016 - 7:11 pm

    I’m suspecting your setup needs to include a vnc-server….

    • Daniel P. Clark
      May 29, 2016 - 8:10 pm

      When you install xrdp it automatically selects the vnc4server package to install as well.

  3. Alfonso Pérez
    July 28, 2017 - 1:52 pm

    Hey man, nice article. Where is that photo from? 🙂

Leave a Reply

Your email address will not be published / Required fields are marked *