tmux Indoctrination

0. Why should I care about your favourite software?

Have you ever felt that slight sense of disdain when recommended something that you don't want to waste time investigating to see whether it is garbage or not?

Every day someone suggests another show, band, film, game, podcast, diet, programming language, linux distro, human - whatever. In my head, if anyone even dares suggest a pizza topping combo outside the holy trinity of {sausage, pepperoni, jalapeno} it feels like being designated to redesign an elementary school algebra course.

This recommendation is not like those, it is thought-out evidence-based praise given by a stubborn man who had to be persuaded for weeks to move from screen. I am here to convert you to the glory of tmux-ism. I've been using it for years and the thought of going without it is in the same ballpark as "Hey, how about we never use the command line anymore?" Plus, you don't even have to change your terminal emulator!

1. OK, so what is tmux?

tmux is a terminal multiplexer. You know how gnome-terminal, for example, can have multiple tabs?

Useful. When you are waiting for one software, like apt-get upgrade, to finish, you can do something else at the same time. But what if you're ssh'd into a server? You have to wait for that boring apt-get upgrade to finish, unless you ssh in again in another tab. An arbitrary trek.

tmux opens tabs in the shell (via ncurses). Solves the ssh problem, makes things more minimalist-looking, and is terminal-independent ⇒ less keyboard shortcuts to remember.

In addition, it can also split tabs into windows known as panes. This allows you to watch something like htop, while testing other features.

2. Alright, I get it. Meh.

You haven't even reached OT VIII (operating tmuxite level 8).

tmux also operates with sessions. Suppose you have a server with several services: Web server, game server, media server. Imagine sshing into that server and being able to restore a tmux session where each service has its own tab, and each tab has multiple panes. One pain for monitoring the services (e.g. apachetop, or the non-daemon mode of game servers), others for editing sites/changing game configs.

With plugins, you can preserve these sessions even after rebooting. So, when I was doing the OSCP, every time I booted up my kali VM, I had this:

First tab for VPNing into the lab. Second for reading/grepping my notes: On book chapters, command-line, course exercises. Third for data: one pane for known passwords and mutation, one for broader network data, one specifically for user notes. Fourth and fifth for one machine each: See picture, usually 3-4 panes, metasploit/tools, machine-specific readme. Sixth for searchsploit: just to have it large, this was before I commonly used the zoom feature. Seventh for services: managing my web-server for RFI, my tftp/ftp for each file transfer. Eighth for proxy: rdesktop, sshing, readme of commonly-used pivots and their credentials.

On my thinkpad, the current sessions are related to OSWP, learning NASM, playing shadowgate, and other things. On different machines, different sessions for different purposes. This makes life so much more organised, and so much less dependent on GUIs.

3. OK, OK. How do I set it up already?

i@pc:~ sudo apt-get install tmux

i@pc:~ wget

i@pc:~ git clone ~/.tmux/plugins/tpm

i@pc:~ tmux

Now you are in tmux, press Ctrl+A, then Shift+I. This uses tmux plugin manager to install tmux-resurrect and tmux-continuum, which allows restoring sessions after reboot.

4. Alright, and how exactly do I use it?

The .tmux.conf you downloaded from here contains a few common rebinds (for some incomprhnsible reason tmux uses Ctrl+B instead of Ctrl+A for the default prefix), UI tweaks, and, makes the plugin manager work with resurrect and continuum.

Ctrl+A is the prefix key, which we will refer to as #, usually pressed before a command inside tmux. Here are some useful commnds:

Within a regular shell:

tmux start a new session, if an old one has been autosaved, tmux-continuum will resurrect it.
tmux a restore a current session.

Within tmux:

#, d detach from the current tmux session (return to regular shell)
#, c create a new tab, usually number n+1 of your total tabs
#, <N> where N is an integer, switch to tab number n
#, z zoom a pane to full-screen, repeating toggles back
#, - create pane via horizontal split (_)
#, \ create a pane via vertical split (|)
#, <A> where A is any arrow key, switch the active pane
#, x remove the current pane (or current tab if there is only one pane)
#, , edit tab name (instead of (0,1,2) have (vpn,apache,cool-code-project))
#, t summon a cool, but useless, clock
#, PGUP allows you to scrollup (via pageup/pagedown or arrow-keys)
#, Ctrl+<A> where A is any arrow key, resize panes. If you hold Ctrl you can press as many arrow keys as you want

Regarding copying and pasting, with panes it can sometimes get annoying:

To quickly use the mouse, you can just zoom the interesting pane #, z, click-drag to select, copy, then zoom back.

In scroll mode (#, PGUP), spacebar will start visual-selection, like in vim, Enter will copy, exiting that mode (Ctrl+C), then #, ], will paste.

5. Anything else?

I've only given you the commands I use the most.

Here is a cheat sheet (though it might have some alternate definitions to my .tmux.conf) and the manual. Also remember with .tmux.conf you can customise tmux's colour scheme, change hotkeys, and add additional plugins.

↑ Top  ⌂ Home