【终端】tmux
1. 前言
看了好多牛逼的渗透打靶教程,我发现很多牛逼的人都喜欢用tmux进行操作,(比如ippsec、红队笔记)。我一直都是用的ssh工具自带的分屏功能,感觉也挺好用的,但是既然这么大佬都会用tmux进行操作。我觉得还是有必要去了解一下,看看这个究竟好不好用。 毕竟很多时候在别的电脑上,我是没有这个ssh工具的(如我现在常用的 xterminal)
2. 工具使用
2.1. 安装
apt install tmux
2.2. 使用
开启鼠标支持
vim ~/.tmux.conf
添加 set -g mouse on
source-file ~/.tmux.conf
基本操作
#会话相关
新建会话:tmux new -s [session_name]
退出会话:ctrl+b d
进入会话:tmux a(attach) -t [session_name]
销毁会话:tmux kill-session -t [session_name]
终端环境查看会话列表:tmux ls
会话环境查看会话列表:ctrl+b s
#窗口相关
创建窗口:ctrl+b c
垂直分屏:ctrl+b %
水平分屏:ctrl+b "
设置窗口大小:ctrl+b alt+方向键
ctrl+b l 相邻的window切换
关闭窗口:ctrl+b &
3. 我的Tmux配置
# 启用鼠标支持(tmux 2.1+版本)
set -g mouse on
set-option -g history-limit 50000
#vi
set-window-option -g mode-keys vi
# 设置 tmux 界面为 256 色
set -g default-terminal "screen-256color"
# 状态栏刷新间隔(秒)- 重要!没有这个时间不会更新
set -g status-interval 1
# 状态栏左侧:会话名
set -g status-left-length 40
set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
# 状态栏右侧:日期和时间
set -g status-right-length 60
set -g status-right "#[fg=cyan]%a %Y-%m-%d #[fg=green]%H:%M:%S"
# 设置窗口标题
set -g set-titles on
set -g set-titles-string "#S:#I.#P #W"
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# ==================== 自动日志记录(保存到启动目录) ====================
# 使用 pipe-pane + ansifilter 将输出保存到启动目录
# 辅助脚本会在创建 window/pane 时添加分隔符
set-hook -g after-new-session 'run-shell "~/bin/tmux-log-helper.sh \"#{window_index}\" \"#{pane_index}\""'
set-hook -g after-new-window 'run-shell "~/bin/tmux-log-helper.sh \"#{window_index}\" \"#{pane_index}\""'
set-hook -g after-split-window 'run-shell "~/bin/tmux-log-helper.sh \"#{window_index}\" \"#{pane_index}\""'
# ==================== END 日志记录 ====================
# 初始化 TPM(必须放在配置文件最后)
run '~/.tmux/plugins/tpm/tpm'