Tmux is a terminal multiplexer an alternative to GNU Screen. In other words, it means that you can start a Tmux session and then open multiple windows inside that session. Each window occupies the entire screen and can be split into rectangular panes.
With Tmux you can easily switch between multiple programs in one terminal, detach them and reattach them to a different terminal.
Tmux sessions are persistent, which means that programs running in Tmux will continue to run even if you get disconnected.
All commands in Tmux start with a prefix, which by default is ctrl+b.
how to use tmux
# syntaxtmux<options><session>##### create a new sessiontmuxnew-ssession_name##### show all running tmux sessionstmuxls##### attach to a sessionroot@Corrosie:~#tmuxlstestSession:1windows (created SunAug909:11:002020)root@Corrosie:~#tmuxattach-session-ttestSession##### tmux options (in the tmux session)Ctrl+bc# Create a new window (with shell)Ctrl+b0# Switch to window 0 (by number ) [IMPORTANT]Ctrl+bn# go to the next screen (right side)ctrl+bp# go to the previous screen (left side)Ctrl+b,# Rename the current windowCtrl+b%# Split current pane horizontally into two panes [IMPORTANT]Ctrl+b" # Split current pane vertically into two panes [IMPORTANT]Ctrl+b o # Go to the next pane (alternative = ctrl+b <terminalscreen number>Ctrl+b x # Close the current paneCtrk+b z # increase the window size of you current terminal to the full size, use this combination again to shrink it to origin size
ctrl+b [ # scroll through your terminal output, use 'q' to quit this feature.##### switching through tmux panesctrl+b <ARROW KEYS> ##### detaching from sessionsctrl+b d # detach from current terminal sessionctrl+b D # detach from the entire terminal session##### kill all tmux sessions# in any terminal:tmux kill-server
tmux script - specific
Here is an example of a tmux script, this script will connect you to your own tmux session. with predefined tmux windows, and tools.
note: this scripts requires that tools are installed, like openVAS, Metasploit, openvpn etc. Also, it is redirecting to local directories that are not present on a default Linux installation. If you would like to try and test this, check out the next subject "tmux script - general example"
#!/bin/bashsudoserviceopenvpnstartsleep2SESSION="$USER"tmuxls>/dev/nullif [ "$?"==1 ]thentmux-2new-session-d-s $SESSION# setup multiple windows to attach 5 tmux sessionstmuxnew-window-t $SESSION:1-n'general usage'tmuxselectp-t1tmuxnew-window-t $SESSION:2-n'recon'tmuxselectp-t2tmuxsend-keys"cd ~/Documents/hacking/useful_repos/recon/autorecon/results"C-mtmuxsend-keys"clear"C-mtmuxsplit-window-v-t2tmuxsend-keys"cd ~/Documents/hacking/useful_repos/recon/autorecon"C-mtmuxsend-keys"clear"C-mtmuxsend-keys"sudo python3 autorecon.py "tmuxnew-window-t $SESSION:3-n'enum/attack'tmuxselectp-t3tmuxsend-keys"cd ~/Documents/hacking/useful_repos/recon/autorecon"C-mtmuxsend-keys"clear"C-mtmuxnew-window-t $SESSION:4-n'msf'tmuxselectp-t4tmuxsend-keys"msfconsole"C-mtmuxsend-keys"clear"C-mtmuxnew-window-t $SESSION:5-n'repositories'tmuxselectp-t5tmuxsend-keys"cd ~/Documents/hacking/useful_repos"C-m# open a terminal and connect to your current session.gnome-terminal--tmuxattach-t $SESSIONelsegnome-terminal--tmuxattach-t $SESSIONfi
tmux script - general example
#!/bin/bashSESSION="$USER"tmuxls>/dev/nullif [ "$?"==1 ]thentmux-2new-session-d-s $SESSION# setup multiple windows to attach 5 tmux sessionstmuxnew-window-t $SESSION:1-n'read /etc/passwd'tmuxselectp-t1tmuxsend-keys"cat /etc/passwd"C-mtmuxnew-window-t $SESSION:2-n'terminal 2 | splitted panes'tmuxselectp-t2tmuxsplit-window-v-t2tmuxsend-keys"cd /etc"C-mtmuxsend-keys"echo 'Note, i am in the /etc directory!'"C-mtmuxnew-window-t $SESSION:3-n'Terminal 3'tmuxnew-window-t $SESSION:4-n'Terminal 4'tmuxselectp-t4tmuxnew-window-t $SESSION:5-n'Terminal 5'tmuxselectp-t5# open a terminal and connect to your current session.tmuxattach-t $SESSIONelsetmuxattach-t $SESSIONfi###### make sure the permissions are correctly set to execute the script