Share a tmux session for pair programming with ssh

Bonnie Eisenman
InstructorBonnie Eisenman
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

By using ssh, you can share a tmux session, making pair programming much easier. We'll learn how to share a tmux session with another user.

[00:00] One of the really neat things that you can use tmux for is pair programing. You can see right here I have two terminal windows open. They're both SSH into the same server.

[00:09] I'm using a simple DigitalOcean Droplet. You can of course set up SSH with your pair programmer however you want, whether that's with another server or with one of your laptops, whichever works best for you.

[00:21] The neat thing here is that in one of these windows, we can type tmux new session -s pair, and it'll launch a tmux session. So far, so good. This is a pretty ordinary thing to do.

[00:38] If I go into the other window, I can run tmux ls, and I can see that there is a tmux session here, which I can also attach to. I'm going to type tmux a, which is a shortcut for attach, -t pair.

[00:52] Now both of these windows, they are separate SSH sessions, and they are attached to the same tmux session. Commands, the pane setup, all of that stuff will be reflected in both. For example, I can do a pane split with Ctrl-b+%, and we see that both sessions reflect the split.

[01:13] Let's go back down to one pane. I'm going to do Ctrl-d to close that extra one. Let's go into vim.

[01:21] This is where it starts to get really cool for pair programing. I can do the quick brown fox jumped over the lazy dog. Obviously, you're going to be wanting to write something a little bit more substantial.

[01:34] The cool thing here is that this happens with barely any lag, and not only do you get to see my code update live, you also get to follow my cursor. You can see how I'm navigating and all of that.

[01:45] Again, this doesn't require any fancy configurations or changes to how you use tmux. You both just have to be sharing the same session.

David Poindexter
David Poindexter
~ 7 years ago

Is there any way, plugin or otherwise, that you can share commands pressed?

For example, I get a new dev to log in and connect to a digitalocean droplet hosting a tmux session. I want to help them with vim.

Text on screen is clearly not enough with vim, they need to see commands I'm pressing in the other non-insert modes.

Thanks!

Shaun
Shaun
~ 7 years ago

This is awesome, one of the best features of tmux. I regularly use the tmate.io service to share tmux sessions when I'm working remotely.

Markdown supported.
Become a member to join the discussionEnroll Today