tmux - a terminal multiplexer

Desktop terminal emulators usually have the feature of tabbed terminals. tmux does something similar on the server side, it's a terminal "window manager" where you can create and close new windows, and especially leave them open and running when you disconnect from the server.

You should try to work inside a tmux window on the server, so when you get interrupted, you can always just detach the window and log off while e.g. upgrades, compiles, backups or other long-lasting operations still keep running.

More than once I damned myself for not starting something inside tmux, so I needed to leave my laptop online for the whole night doing nothing, just to keep the ssh session running. xD

But when you just run tmux without configuring it, you can't scroll up with your terminal emulator's scrollbar, which I find really annoying. The following fixes this:

# Create or edit the tmux configuration file at ~/.tmux.conf
vim ~/.tmux.conf
# and enter:

# Sane scrolling
# alternatively scroll inside tmux with CTRL+B [
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

Psst! In case you're a fan of solarized, there's a tmux color scheme for it: https://github.com/seebi/tmux-colors-solarized/ But beware of problems with colors in tmux over ssh, I never managed to really convince tmux to use 16 colors for true solarized instead of 8 or 256.

Now to the minimum tmux commands one needs to know to work inside tmux:

# start a new tmux session with a single window
tmux
# tmux is controled via single key commands entered after you pressed CTRL+B
# create a new window
CTRL+B C
# switch to next window
CTRL+B N
# switch to previous window
CTRL+B P
# close a window (no CTRL+B in front, just like you'd close a virtual terminal)
# By closing the last window, you'll close the tmux session, too.
CTRL+D

# If you want to keep your windows open and running, "detach" your session with
CTRL+B D
# You can now savely disconnect from your server.
# Reattach your last tmux session with
tmux attach
# just entering "tmux" without "attach" will create a new session.
# Closing it with CTRL+D and then entering "tmux attach"
# will bring back your old session

tmux also supports named sessions and windows. I used named sessions for a while to have the irssi irc client always running on my server and then attached the specific irssi session from my laptop, but I'm much happier now with ZNC.

The above commands should be enough to use tmux for administration tasks, but tmux is much more powerfull than that - some of that power might come in handy for whatever you want to have running on your server.

Remarks? Additions? Corrections? For anything you want to tell me about this blog post, feel free to send me an email[*].
Despite having no comments section (isn't that easy with a static site generator and without relying on a proprietary 3rd party service), I greatly appreciate direct feedback. 😉 In case of additions, I'll mention the name from the mail if you don't object.

[*]: Mails from small independent mailservers are my mailserver's favourite! ❤
If you don't want to keep one on your own, you can pay various admins about 1€ per month to do so for you, e.g. at posteo, mailbox.org, jit-creatives, or at most webhosting providers like netcup or 1&1 in case you want to have your own domain name on top.