Tmate – Securely Share SSH Terminal Session with Linux Users

[‘

n

tmate is a clone of tmux (terminal multiplexer) that provides a secure, instant and easy-to-use terminal sharing solution over an SSH connection. It is built on top of tmux; you can run both terminal emulators on the same system. You can either use the official servers at tmate.io or host your own tmate server.

n

The following figure shows a simplified architecture diagram with the different components of the tmate (obtained from the project website).

n

tmate - Simplified Architecture Diagram
tmate – Simplified Architecture Diagram

n

How Tmate Works?

n

When launching Tmate, it will first establish an ssh connection to tmate.io server in the background through libssh. Once the connection is established, a 150 bits session token is generated for each session. Trusted users can use this generated token to access terminal session.

n

How to Install Tmate in Linux

n

Tmate is available to install from the default repositories of most Linux distributions using package manager as shown.

n

In Debian and Ubuntu-based Linux distributions, use the following PPA to install Tmate.

n

$ sudo apt-get install software-properties-commonrn$ sudo add-apt-repository ppa:tmate.io/archive   rn$ sudo apt-get update                        rn$ sudo apt-get install tmatern

n

On Fedora distribution, use the following dnf command.

n

$ sudo dnf install tmatern

n

On Arch Linux, you can install it from AUR as shown.

n

$ yaourt -S tmatern

n

In openSUSE, you can use zypper command to install it.

n

$ sudo zypper in tmatern

n

On Gento, you can use emerge to install it.

n

$ sudo emerge tmatern

n

On other Linux distributions such as CentOS and RHEL, you can download sources from https://github.com/nviennot/tmate and compile and install with the following commands.

n

$ ./autogen.sh rn$ ./configure rn$ make     rn$ sudo make installrn

n

How to Share Your Terminal Using Tmate

n

Once you have installed tmate, it uses both ~/.tmux.conf and ~/.tmate.conf configuration files. Everyone you share your terminal with, will be using your tmux config and your key bindings. The terminal is forced to 256 colors and UTF-8, so you don’t need to pass -2 as you may be used to do with tmux.

n

To launch tmate, run the following command, which makes the program to establish an ssh connection to tmate.io (or your own server) in the background through libssh.

n

$ tmate rn

n

Tmate Session
Tmate Session

n

Then you can share the ssh session connection parameters using generated token ID (for example: [emailxa0protected] in this case) with your mates so that they can access your terminal.

n

To access your terminal, your friend/colleagues needs to run the following ssh command in their terminal.

n

$ ssh [emailxa0protected]rn

n

Tmate Session Sharing with Friends
Tmate Session Sharing with Friends

n

To show tmate’s log messages, including the ssh connection string, run:

n

$ tmate show-messagesrn

n

Tmate Log Messages
Tmate Log Messages

n

tmate also allows you to share a read-only view of your terminal. The read-only connection string can be retrieved with tmate show-messages as shown in the above screenshot.

n

To terminate the program, run the exit command.

n

$ exitrn

n

For more information on how tmate works, how to run it as a daemon and host your own tmate server, go to the project website: https://tmate.io/.

n

Tmate is a fork of tmux that provides a secure, instant terminal sharing solution. In this article, we have shown how to install and use tmate in Linux and use it to share your terminal with your mates. Feel free to share your thoughts with us via the feedback form below.

n

‘]