Terminal multiplexer minimal tutorial
utils productivityTerminal multiplexer
is a software that can multiplex several separate pseudoterminal-based login sessions inside one terminal.
Main features:
- Persistence - similar to
nohup
, permits to disconnect and reconnect without terminating running processes - Multiple windows - split-screens, several windows to have several terminals on one screen.
- Session sharing - multiple users can connect to the same session.
Let’s consider one popular Terminal Multeplexer - tmux
.
Installation
sudo apt-get install tmux
Basic abstractions
- Session - aggregate and controls several terminals and processes
- Window - can be split into several
panes
, a session can have multiple windows. - Pane -
window
can be divided intopanes
- Control key - every control command will look like
*PREFIX KEY* + *COMMAND KEY*
wherePREFIX KEY
isCtrl+B
by default. In this tutorial, I will useC-b
instead ofCtrl+B
Basic functionalities
Here are some basic functionalities:
- when ssh is disconnected session will persist
- sessions for different tasks
- connect to the shell of different user
Panes
C-b
+ %
= split left/right
C-b
+ "
= split up / down
C-b
+ left/right
= go to prev/next pane
exit
or C-d
= close pane
Windows
C-b
+ c
= new window
C-b
+ p/n
= go to prev/next window
C-b
+ <number>
= go to window <number>
Sessions
C-b
+ d
= detach session
tmux ls
= list of sessions
tmux attach -t 0
= attach to session 0
tmux new -s database
= create session named “database”
Mouse control
Add this to .tmux.conf
Shared sessions
tmux
can also create shared sessions
and different users can attach to this session at the same time.
Create
Modify socket permissions to get access for other users in group tmux
Attach
Attach Read-only
? Problem: two users connected to a shared session will use the same session. Active pane and window are connected to the session, so they won’t be able to look at different windows at the same time, and type in different panes simultaneously.
! Solution: grouped sessions
Grouped sessions
grouped sessions
allow to share windows and panes between sessions and work in different windows and panes.
Usage optimized
Here we will discuss some configurations and best practices to foster usage of tmux and make it more transparent and easier
Some hack to organize multiuser interaction with shared sessions
Shared sessions are implemented with unix sockets, and there is no functionality to look at all shared sessions. To organize shared sessions on the server for a small team we can do the following:
Where <USERS>
means add all necessary users manually or list all users with other utils.
Then we can add some sh-scripts to start
, attach
and list
shared sessions.
wemux - some wrapper on top of tmux for multiuser access (TODO: check if it works on Ubuntu)