Alastair Bateman

Tmux Configuration

Tmux is a handy Linux utility which, like screen, can emulate multiple screens over a single console session. It’s really handy for maintaining sessions over ssh instead of risking losing everything you’re working on because your network connection has been temporarily interrupted.

.bash.rc

In order to start tmux each time I connect to a server via ssh I add the following to the end of my ~/.bashrc.

if [[ -z "$TMUX" ]] && [ "$SSH_CONNECTION" != "" ]; then
    tmux attach || tmux new-session
fi

.tmux.conf

I’ve added the following to my ~/.tmux.conf. The first three lines remove the default ‘prefix’ combo Ctrl-b and replace it with Ctrl-a. This is because it’s the default for screen which I’d used previously and it feels a bit more usable than stretching for Ctrl-b

unbind C-b
set -g prefix C-a
bind C-a send-prefix
# if run as "tmux attach", create a session if one does not already exist
new-session -n $HOST

Useful Shortcuts

ShortcutDescription
Ctrl-a pGo to the previous tab
Ctrl-a nGo to the next tab
Ctrl-a cCreate a new tab
Ctrl-a dDetach from tmux

Plus a lot more: