Last Updated: September 09, 2019
· mislav

Easily invite a person to pair with you in tmux

The long

  1. Verify that sshd is running on your machine:

    nc -zv localhost 22
  2. Get your external IP (make sure your router forwards the SSH port to you):

  3. Get your pair's public key. You can fetch them from GitHub with github-auth:

    gh-auth add mislav
  4. Tell them to attach to your tmux session, which you can get with:

    tmux display -p '#{session_name}'

The short

I created a single command called pair that encapsulates all of the above steps and copies the ssh command on clipboard that you can paste to your pair. To pair with me, you would use it like so:

pair mislav

And a command would be copied to your clipboard:

ssh -t <MY-USER>@<MY-IP> 'tmux attach -t <TMUX-SESSION>'

This single line allows your pair to connect directly to tmux in one step.

Keep in mind that this gives your pair access to your computer (they effectively become you on your machine) and they can connect to any other tmux session as well without you knowing. If this level of access is unacceptable, consider pairing in a dedicated environment such as on a shared server or virtual machine.

A tip about syntax highlighting: if one of the people is using Solarized, then both need to have their terminals configured for Solarized, otherwise colors will look wrong and some code might even be invisible.

5 Responses
Add your response

Tmux will change your life. As @mislav said if you don't fully trust (or know) who you're pairing with, you can spin up a box on Nitrous.IO and create a tmux session there. It's safe, easy to add collaborators to your box, and it's free.

disclaimer: I'm a co-founder

over 1 year ago ·

@mislav - Great tip! I definitely need to check out your pair command and also gh-auth. Very cool work there. On a related note, I tried tmate this week with a co-worker and it was really easy to use for pairing as well.

over 1 year ago ·

I actually prefer tweemux, because you don't necessarily need to worry about having a router forward a port to you.

over 1 year ago ·

Tks for the post, it was pretty useful! One thing that I had to do besides what you've written was adding a config to my /etc/sshd_config to use the new authorized keys:

AuthorizedKeysFile /Users/hugobarauna/.ssh/authorized_keys

Did you had to do something like that also?

over 1 year ago ·

sshd should use your $HOME/.ssh/authorized_keys by default. I'm not sure why you had to enable it explicitly.

over 1 year ago ·