Emergency shell access with tmate
Over Your Shoulder
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
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.
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).
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).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.