Emergency shell access with tmate

Over Your Shoulder

© Lead Image © Cathy Yeulet, 123RF.com

© Lead Image © Cathy Yeulet, 123RF.com

Article from Issue 222/2019
Author(s):

Tmate lets you access the shell session of a remote computer – even through a router.

Your parents or friends have replaced an unmanageable Windows installation with an easy-to-use Linux variant, and they have designated you as their remote admin. To access the system from afar, you resort to a GUI-based tool such as TeamViewer or AnyDesk. All is well until the graphical user interface (GUI) for the computer you need to access breaks. Suddenly, your GUI-based remote access tool won't work anymore, because you don't have access to an X server.

Tmate [1], which stands for "team mate," offers a convenient solution for remote access in situations when you can't depend on the graphical tools. This fork of the popular tmux [2] terminal multiplexer has significantly more functions than the original. Tmux is functionally similar to Screen [3] in some ways. You can use tmate to create and manage remote virtual sessions within a terminal or terminal emulator.

Self Hosted

Tmate is not only suitable for external help, but also lets developers collaborate on software. Technically, the tool uses Secure Shell (SSH) to establish a secure connection to the tmate.io server, which is under the control of the tmate developers.

Alternatively, you can run tmate on your own server. The resource requirements are kept within such narrow limits that a recent Raspberry Pi or a similarly equipped single-board computer is sufficient. The machine only generates an SSH ID and some URLs for different types of sessions – SSH or web sessions in read-only mode or with full access.

Installing tmate is easy, because the program is available from the package sources of all common distributions. For Arch Linux, use the AUR user archive; for Debian and its derivatives including Ubuntu, just type:

sudo apt install tmate

On Fedora, this translates to:

sudo dnf install tmate

Creating Keys

After the installation, which occupies only a few kilobytes on your disk, you need to create a key pair for SSH (if it does not already exist). As shown in Figure 1, this is done by typing:

ssh-keygen -t rsa -b 4096
Figure 1: An SSH key pair is quickly created. In contrast to normal use, the public key remains on the computer. The computers only exchange randomly created IDs or URLs via the software at startup.

Answer the individual prompts by pressing the Enter key. You can assign a password for the key, but in our example this is not necessary for home use.

Tmate uses the RSA cryptographic procedure with a secure key length of 4096 bits. By default, the keys are located in the hidden .ssh/ directory in your home directory; tmate will now find them automatically when you use the tool. You need to generate these keys on each computer involved if a key pair does not already exist there.

When you open a connection, the program creates a 150-bit session token. It then launches a tmux server in a sandbox without a filesystem and user rights, but with its own namespace to isolate the server from other processes. To make this possible, the software opens all the files it needs for running the tmux server before they end up in the sandbox.

These measures are intended to limit the leverage of potential exploits targeting the tmux server. An attacker would not be able to access other sessions. The technical principles are explained in detail in a 10-page paper [4].

SSH ID or URL

After starting tmate as a user for the first time, a bar at the bottom of the terminal window shows a random SSH ID for establishing an SSH session in Read/Write mode (Figure 2). It is best to copy this line to the clipboard, because it disappears after a short time.

Figure 2: After the application starts, it displays a randomly generated SSH ID at the bottom of the terminal.

If you did not react fast enough, you can get the data including the other IDs or URLs back on the screen with the tmate show-messages command. This command is also used for logging during a session (Figure 3).

Figure 3: Using the tmate show-messages command, the program displays the SSH IDs and URLs (only valid for this session), as well as the running application's logs.

While the SSH ID displayed at the start of tmate creates a read-write session in a terminal, tmate show-messages also shows an ID for a terminal session that supports read-only access. In addition, the program provides two URLs that support the same procedure in the browser (Figure 4).

Figure 4: Tmate not only works in the terminal, but also in the web browser. This also applies if you host tmate yourself.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Remote Pair Programming

    The best way to save money on software development is to get it right the first time. Pair programming, an agile technique, saves development costs by putting two coders to work on the same code. Visual Studio Code and tmate bring the promise of pair programming to remote workers.

  • Multi-Tasking

    Operate multiple terminal sessions in a single window.

comments powered by Disqus