Re-attachable shell for long-running tasks on remote host: tmux



This is almost too simple for a whole wiki page, but snippets that maybe useful in emergency situations deserve a page by definition ...

Some tasks run too long for one "office chair session". Some other tasks require a lot of shell environment preparation.

In both situations a long-lived shell that can be accessed from different client machines can be very useful.

tmux provides such a shell.

tmux snippets

The following examples assume that the detachable shell shall run on a remote machine.

Obviously, tmux has to be installed:

sudo apt-get install tmux

Creating a detachable shell

ssh user@host
# start whatever task shall run


Press Ctrl-b d, i.e. press and hold Control, press B, unhold Control, press D.


ssh user@host
tmux attach

Frequently used hotkeys


To enter scrolling press Ctrl-b [. Now cursor up/down and page up/down allow arbitrary scrolling. To quit scrolling, press q (for quit).

Frequently used options

-L socket-nameUses specified socket-name instead of 'default'. Useful to run and distinct multiple tmux daemons.
-S socket-pathUses specified socket-path instead of default path and name. Useful to run and distinct multiple tmux daemons.

Further features and reading

tmux can do much more, i.e. run multiple commands (i.e. shells) and so on.

Just read the tmux(1) manpage, especially chapters KEY BINDINGS, COMMANDS, and below.