tmux lets you run and manage multiple terminal sessions to remote servers from a single window. It is a terminal emulator that runs inside a terminal (such as PuTTY, Windows Terminal, or any other Linux, BSD or SunOS shell).
tmux will preserve your session regardless of what happens to your session. For example, I’m using my laptop to shell into my remote servers runnig on Raspberry Pi, Virtual Box and AWS EC2. Quite often my laptop goes into sleep mode, the PuTTY session times out, or I accidently close my PuTTY window.
When this happens, the remote shell will receive a SIGHUP (hangup) signal telling the shell that the terminal running the programs is now gone. This consequently terminates everything running from the shell. The exception to this is when you run a process in the background the nohup
and &
commands.
However, if I was running my sessions through tmux, I can reconnect to tmux session and pick all where i left off, all processes all intact.
Install tmux on Raspberry Pi
$ sudo apt update
$ sudo apt install tmux
Start a new tmux session and give the session an identifying name (let’s call it admin1) relating to the work you’re doing.
$ tmux new -s admin1
List tmux sessions running
$ tmux ls
Re-attach to a previous session (admin1)
$ tmux attach -t admin1
Split Panes and add a horizonal, vertical or both.
Horizontal | [ctrl]+b then % |
Vertical | [ctrl]+b then “ |
Change Panes
Move between panes | [ctrl]+b then arrow keys |
Resize panes | [ctrl]+b then : (then type resize-pane -D 10) -D means resize downwards 10 is the number of lines to grow Also: -U resize upwards -L resize left – R resize right |
Create configuration file to bind shortcut keys
$ vim .tmux.conf
Paste this syntax into the configuration file
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
Press Ctrl+b then H, J, K, or L to resize in that direction. The -r option repeats command when held down.
Other
Close a pane | [ctrl]+b then x (then y to confirm) |
Kill all other panes | [ctrl]+b then ! |
Break pane into its own window | [ctrl]+b : (then type break-pane) |