tmux - Terminal Multiplexer
Why use tmux?
• Keep the session opened on server even after client shut down
• Share a shell session
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Start tmux
ssh ubuntu@10.0.3.152
sudo apt install tmux
tmux # start tmux server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Window Commands
ctrl-b c # create new windows
ctrl-b & # kill the current window
ctrl-b , # rename window
ctrl-b ? # list all key bindings
Ctrl-b q # show pane numbers
# (used to switch between panes)
Ctrl-b o # switch to the next pane
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Moving Between Windows
Ctrl-b n # move to the next window
Ctrl-b p # move to the previous window
Ctrl-b l # move to the previously selected window
Ctrl-b w # list all windows / window numbers
Ctrl-b window number # move to the specified window number
# the default bindings are from 0 -- 9
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tiling Commands
ctrl-b % # split vertically
ctrl-b " # split horizontally
ctrl-b o # goto next pane
ctrl-b q # show pane numbers, when the numbers show up
# type the key to go to that pane)
ctrl-b { # move the current pane left
ctrl-b } # move the current pane right
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Make a pane its own window
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sessions Management Commands
• Allows multiple windows opened in a single ssh session
tmux ls # list opened sessions
# or
tmux list-sessions
tmux new -s backupsession # create new session
htop
ctrl-b d # detach from a session - back to the shell
ps aux | grep htop # session still running
# logout from ssh session
logout
• Session remains opened after you log out from ssh session
ssh ubuntu@10.0.3.152
tmux list-sessions # list opened sessions
tmux attach -t backupsession # attach to session
tmux kill-session -t backupsession # kill a session
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sharing Sessions
• Need to ssh login a common server with the same username
# First user
ssh ubuntu@10.0.3.152
tmux new-session -s this_is_shared
# Second user
ssh ubuntu@10.0.3.152
tmux list-sessions
tmux attach -t this_is_shared
• We're now sharing the same session between 2 different people from 2 different ssh sessions
• Commands typed in this_is_shared are visible by 2 different people
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Advanced Usage
• Sharing Linux Terminal Sessions With Tmux and Screen
• tmux Cheat Sheet
Index