Tools

tmate: Instantly Share Terminal Session With Other Linux Users

Want to share terminal with other users over a secure network? tmate is your friend for sharing SSH sessions.

Rishi Raj Gautam
Rishi Raj Gautam

Table of Contents

tmate is a terminal multiplexer with instant terminal sharing i.e, it enables sharing your terminal session with a number of trusted users. It is similar to the concept of multicasting. All the recipients get to view the terminal session over an SSH connection.

tmate is actually a fork of Tmux, a popular terminal multiplexer that lets you use several programs in a single Terminal. It gives you an IDE kind of experience in the terminal window.

How tmate allows terminal sharing!

Share terminal session over SSH by using tmate

On starting Tmate, it will first establish SSH (secure shell) connection to tmate.io website which acts as a server on the internet. Once the connection is established, a random SSH URL token is generated for each session. The ssh URL ID will be displayed at the bottom of your terminal session. Now the terminal is ready to be shared.

Trusted teammates can access your terminal session through the URL ID and can use it as long as the connection is active. In my opinion, tmate’s best application is to assist in group projects, or to debug the project with a team of developers, or get technical support on the remote network.

How to install tmate in Linux

tmate is a popular program and hence it is available in the default repositories of most Linux distributions. All you have to do is to use your Linux distribution’s package manager and install it.

I’ll list some of the examples for the sake of your comfort.

In Debian and Ubuntu-based Linux distributions, use this command:

sudo apt install tmate

For Fedora, you can use this command:

sudo dnf install tmate

tmate is available in AUR so you can use your favorite AUR Helper in Arch Linux:

yaourt -S tmate

In openSUSE, you can zypper to install tmate:

sudo zypper in tmate

How to share terminal with tmate

Let’s see the steps to use tmate and share terminal session with others.

Step 1: Generate SSH Key-Pair

To use tmate, we need to create an SSH key-pair. The tmate program first establishes a secure SSH connection of host machine with tmate.io website using that SSH key pair.

Also, the authentication of every client machines that try to connect to host terminal is also made by tmate.io server through same ssh keys. Hence, every system should have their SSH key generated.

Use this command to generate ssh-key:

ssh-keygen -t rsa

Step 2: Use tmate on host system

On the system where the terminal session will be used, open a terminal and enter “tmate” command in your terminal.

tmate

A tmate sessions screen looks like:

tmate session

You would notice that in a few seconds, the SSH session ID will disappear. You need this session ID so that others can view your session.

To find the tmate sesson id, use the following command:

tmate show-messages
Find tmate session ID
Get tmate ssh session id

Step 3: Access tmate session

Share the SSH session ID with your trusted teammates and they can access your terminal using this command in their own terminal.

ssh <SSH_Session_ID>

For example, in my case, it would be:

ssh YKiCguXm84rZmTiv9[email protected]

By default, tmate allows both read and write access to the shared terminal session. Which means that anyone connected to your session can run commands in your terminal.

If you don’t want that, you can share the read-only session id. If you look at the output of the show-messages command, you’ll notice there are several session IDs. You can find the read-only session id there.

Not only with SSH, you can share your terminal through web URL as well. You can get the web session URL in the show-messages output (as shown in the picture above).

Step 4: End tmate session

Use “exit” command to exit the tmate session.

exit

Do you like tmux?

Since tmate is based on tmux, you can use all tmux commands in tmate terminal sessions. This is very useful for Linux power users.

I hope you liked this quick article on sharing terminal with tmate. What’s your experience with it. Do share with us.



Join the conversation.