tmux
2026/5/29工具通用工具工具通用工具tmux终端大约 4 分钟
tmux
是什么
tmux 是终端复用工具,可以在一个终端里管理多个会话、窗口和面板。
CTF 中适合:
- 一边跑服务,一边写 exploit
- 断开 SSH 后保持任务运行
- 同时查看日志、调试器、脚本输出
- 比赛时组织多个题目的终端
安装与配置
Ubuntu/Kali:
sudo apt update
sudo apt install tmuxmacOS:
brew install tmux验证:
tmux -V基本用法
新建会话
tmux new -s ctf分离会话
按:
Ctrl+b 然后 d恢复会话
tmux attach -t ctf查看会话
tmux ls分屏
Ctrl+b 然后 %
Ctrl+b 然后 "更多命令
会话管理
# 新建会话
tmux new -s ctf
tmux new -s web -n "burp"
tmux new -s pwn
# 列出会话
tmux ls
# 连接会话
tmux attach -t ctf
tmux a -t ctf
# 分离会话
tmux detach
# 或 Ctrl+b, d
# 杀死会话
tmux kill-session -t ctf
# 重命名会话
tmux rename-session -t old new窗口管理
# 新建窗口
Ctrl+b, c
# 切换窗口
Ctrl+b, n # 下一个
Ctrl+b, p # 上一个
Ctrl+b, 0-9 # 指定编号
# 关闭窗口
Ctrl+b, &
# 重命名窗口
Ctrl+b, ,
# 列出窗口
Ctrl+b, w面板管理
# 水平分屏
Ctrl+b, %
# 垂直分屏
Ctrl+b, "
# 切换面板
Ctrl+b, 方向键
# 关闭面板
Ctrl+b, x
# 最大化/恢复面板
Ctrl+b, z
# 调整面板大小
Ctrl+b, Ctrl+方向键
# 循环面板布局
Ctrl+b, Space面板布局
# 切换布局
Ctrl+b, Alt+1 # 水平均分
Ctrl+b, Alt+2 # 垂直均分
Ctrl+b, Alt+3 # 主水平
Ctrl+b, Alt+4 # 主垂直
Ctrl+b, Alt+5 # 平铺配置文件
基本配置
创建 ~/.tmux.conf:
# 修改前缀键
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# 启用鼠标
set -g mouse on
# 设置历史记录行数
set -g history-limit 50000
# 状态栏
set -g status-bg colour235
set -g status-fg colour136
set -g status-left '[#S]'
set -g status-right '%Y-%m-%d %H:%M'
# 窗口编号从 1 开始
set -g base-index 1
setw -g pane-base-index 1
# 快速重载配置
bind r source-file ~/.tmux.conf \; display "Config reloaded!"快捷键配置
# Vim 风格面板切换
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Alt+方向键切换面板(无需前缀键)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# 更方便的分屏
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"复制模式
# 进入复制模式
Ctrl+b, [
# 开始选择(Vi 风格)
Space
# 复制
Enter
# 粘贴
Ctrl+b, ]
# 搜索
Ctrl+b, [ 然后 /CTF常用技巧
一题一个会话
tmux new -s web-sqli
tmux new -s pwn-ret2libc远程服务保持运行
在服务器上启动靶场或脚本后分离会话,断开 SSH 不会马上停止。
推荐布局
左上: 编辑 EXP
左下: 运行 EXP
右上: gdb / 日志
右下: nc / curl / python 临时命令比赛中的使用
# 创建题目会话
tmux new -s web1
tmux new -s web2
tmux new -s pwn1
tmux new -s crypto1
# 切换会话
Ctrl+b, s # 会话列表日志记录
# 记录面板输出
tmux pipe-pane -o "cat >> ~/tmux.log"
# 停止记录
tmux pipe-pane
# 使用 script 命令
script -a session.log快速部署脚本
#!/bin/bash
# setup-tmux.sh - 创建 CTF 工作环境
# 创建会话
tmux new-session -d -s ctf
# 创建窗口
tmux new-window -t ctf -n "edit"
tmux new-window -t ctf -n "run"
tmux new-window -t ctf -n "debug"
tmux new-window -t ctf -n "net"
# 在窗口中运行命令
tmux send-keys -t ctf:edit "cd ~/ctf && vim solve.py" C-m
tmux send-keys -t ctf:run "cd ~/ctf" C-m
tmux send-keys -t ctf:debug "gdb ./vuln" C-m
# 连接到会话
tmux attach -t ctf常见问题
快捷键不熟
先只记三个:新建、分屏、分离。熟练后再配置。
attach 失败
先 tmux ls 查看会话名。
复制粘贴麻烦
Windows Terminal、iTerm2、VS Code 终端都有自己的复制方式,初学阶段不用深配 tmux 复制模式。
配置不生效
# 重载配置
tmux source-file ~/.tmux.conf
# 或使用快捷键(如果配置了)
Ctrl+b, r面板太多
# 关闭当前面板
Ctrl+b, x
# 最大化当前面板
Ctrl+b, z
# 关闭其他面板
Ctrl+b, ! # 将当前面板拆分为独立窗口会话丢失
1. 检查 tmux 是否还在运行: tmux ls
2. 检查 SSH 连接是否断开
3. 使用 tmux 自动恢复插件关联
- Linux 基础命令
- WSL
- GDB+pwndbg
- Docker