There’s a lot of talk about remote pair programming, but the fact is it can be a pain to set up. Using iChat screen sharing is a popular method, but can feel a little cludgy, and doesn’t work for developers running linux. Here’s another method using reverse ssh tunnels and screen -x we use a lot at Beezwax.
First thing I need is a way for my pair to ssh into my laptop. If I don’t have an ssh port exposed to the internet through a public ip (I usually don’t) I’ll need to do some reverse ssh tunnel magic.
Running a reverse ssh tunnel.
All I need is a public server that my pair and I can both ssh to, which will act as a bridge. We usually use one of our development slices.
I run this command from my local machine to start the ssh tunnel.
$ ssh -nvNT -R 2222:localhost:22 firstname.lastname@example.org
I like to use this set of options for my ssh tunnels. The -R means that we’re forwarding a local port (reverse tunneling). The left number is the remote port which will forward input. The right number is the port on my local box I want the remote port to forward to.
Now public.beezwax.net will forward its port 2222 to my local box’s ssh port.
Now my pair can ssh to the public server:
$ ssh email@example.com
From there she’ll ssh to localhost on the port our ssh tunnel is running on, but it’s not localhost. It’s my laptop.
$ ssh guest@localhost -p 2222
You’ll need a guest login setup on your local machine and to make sure that remote login is enabled.
After authenticating my pair will have an ssh session on my laptop.
Now I need to set up screen so that we can both share a terminal.
Setting up screen for multiple users.
The first time you do this you may need to set the ‘sticky bit’ on screen.
$ sudo chmod u+s `which screen`
I put this line in my ~/.screenrc to tell screen to enable multiuser functionality.
Don’t worry, I still need to explicitly allow someone to connect from within screen.
I’ll start a screen session.
Here is where I give my pair permission to share my screen session.
Ctrl+A :acladd guest
My pair joins my screen session with the -x flag. She’ll enter my username followed by "/" to connect
$ screen -x sam/
Now we’re both looking and controlling the same terminal session. We can run vi or emacs (sorry no textmate), while we talk over Skype, and since this isn’t screen sharing there’s very little lag.