Share your Linux terminal with tmate

Tmate expands your options for session sharing with the Linux terminal.
7 readers like this
7 readers like this

As a member of the Fedora Linux QA team, I sometimes find myself executing a bunch of commands that I want to broadcast to other developers. If you've ever used a terminal multiplexer like tmux or GNU Screen, you might think that that's a relatively easy task. But not all of the people I want to see my demonstration are connecting to my terminal session from a laptop or desktop. Some might have casually opened it from their phone browser—which they can readily do because I use tmate.

Linux terminal sharing with tmate

Watching someone else work in a Linux terminal is very educational. You can learn new commands, new workflows, or new ways to debug and automate. But it can be difficult to capture what you're seeing so you can try it yourself later. You might resort to taking screenshots or a screen recording of a shared terminal session so you can type out each command later. The only other option is for the person demonstrating the commands to record the session using a tool like Asciinema or script and scriptreplay.

But with tmate, a user can share a terminal either in read-only mode or over SSH. Both the SSH and the read-only session can be accessed through a terminal or as an HTML webpage.

I use read-only mode when I'm onboarding people for the Fedora QA team because I need to run commands and show the output, but with tmate, folks can keep notes by copying and pasting from their browser to a text editor.

Linux tmate in action

On Linux, you can install tmate with your package manager. For instance, on Fedora:

$ sudo dnf install tmate

On Debian and similar distributions:

$ sudo apt install tmate

On macOS, you can install it using Homebrew or MacPorts. If you need instructions for other Linux distributions, refer to the install guide.

Screenshot of terminal showing the options for tmate sharing: web session (regular and read-only) and ssh session (regular and read-only)

(Sumantro Mukherjee, CC BY-SA 4.0)

Once installed, start tmate:

$ tmate

When tmate launches, links are generated to provide access to your terminal session over HTTP and SSH. Each protocol features a read-only option as well as a reverse SSH session.

Here's what a web session looks like:

Screenshot showing tmate terminal window and 2 versions of sharing sessions demonstrating the same code

(Sumantro Mukherjee, CC BY-SA 4.0)

Tmate's web console is HTML5, so, as a result, a user can copy the entire screen and paste it into a terminal to run the same commands.

Keeping a session alive

You may wonder what happens if you accidentally close your terminal. You may also wonder about sharing your terminal with a different console application. After all, tmate is a multiplexer, so it should be able to keep sessions alive, detach and re-attach to a session, and so on.

And of course, that's exactly what tmate can do. If you've ever used tmux, this is probably pretty familiar.

$ tmate -F -n web new-session vi  console

This command opens up new-session in Vi, and the -F option ensures that the session re-spawns even when closed.

A screenshot of the terminal showing the output after using the new-session and -F options: connection information for either a web session (regular or read-only) or ssh session (regular or read-only)

(Sumantro Mukherjee, CC BY-SA 4.0)

Social multiplexing

Tmate gives you the freedom of tmux or GNU Screen plus the ability to share your sessions with others. It's a valuable tool for teaching other users how to use a terminal, demonstrating the function of a new command, or debugging unexpected behavior. It's open source, so give it a try!

What to read next
Tags
Hey, open source folks! I am Sumantro, hailing from India (the eastern part - former capital during the British era AKA Kolkata). I love sharing knowledge and writing about technology and experiences (mostly that I try every day).

2 Comments

Similarly there is also upterm (upterm.dev [owenthereal/upterm], not the terminal emulator written in JS [railsware/upterm]) -- I can't remember now what made me switch to it but it was something along the lines of tmate being tmux 2. While upterm is independent of tmux, it can be used with tmux very well. It lacks a web console though.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.