介绍
我刚刚在 CentOS 7 机器上安装了 tmux,但遇到了一个令人困惑的问题。每当我尝试使用tmux
或启动会话时tmux new -s session-name
,它都会在提示符中输出随机字符串,并且无法启动。
$ tmux
$ 1;2c
我不知道该怎么办。
tmux.conf
我的 tmux 配置位于~/.tmux.conf
并配置如下。
setw -g mode-keys vi
# 12 hour clock
set-window-option -g clock-mode-style 12
# reload tmux.conf
bind r source-file ~/.tmux.conf \; display-message " ✱ ~/.tmux.conf is reloaded"
我还注意到生成了一些错误日志,如下所示。
tmux-client-6310.log
got 18 from server
got 3 from server
tmux-server-6312.log
server started, pid 6312
socket path /tmp/tmux-1000/default
new client 8
loading /etc/tmux.conf
/etc/tmux.conf: #Prefix is Ctrl-a
/etc/tmux.conf: set -g prefix C-a
/etc/tmux.conf: bind C-a send-prefix
/etc/tmux.conf: unbind C-b
/etc/tmux.conf:
/etc/tmux.conf: set -sg escape-time 1
/etc/tmux.conf: set -g base-index 1
/etc/tmux.conf: setw -g pane-base-index 1
/etc/tmux.conf:
/etc/tmux.conf: #Mouse works as expected
/etc/tmux.conf: setw -g mode-mouse on
/etc/tmux.conf: set -g mouse-select-pane on
/etc/tmux.conf: set -g mouse-resize-pane on
/etc/tmux.conf: set -g mouse-select-window on
/etc/tmux.conf:
/etc/tmux.conf: setw -g monitor-activity on
/etc/tmux.conf: set -g visual-activity on
/etc/tmux.conf:
/etc/tmux.conf: set -g mode-keys vi
/etc/tmux.conf: set -g history-limit 10000
/etc/tmux.conf:
/etc/tmux.conf: # y and p as in vim
/etc/tmux.conf: bind Escape copy-mode
/etc/tmux.conf: unbind p
/etc/tmux.conf: bind p paste-buffer
/etc/tmux.conf: bind -t vi-copy 'v' begin-selection
/etc/tmux.conf: bind -t vi-copy 'y' copy-selection
/etc/tmux.conf: bind -t vi-copy 'Space' halfpage-down
/etc/tmux.conf: bind -t vi-copy 'Bspace' halfpage-up
/etc/tmux.conf:
/etc/tmux.conf: # extra commands for interacting with the ICCCM clipboard
/etc/tmux.conf: bind C-c run "tmux save-buffer - | xclip -i -sel clipboard"
/etc/tmux.conf: bind C-v run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"
/etc/tmux.conf:
/etc/tmux.conf: # easy-to-remember split pane commands
/etc/tmux.conf: bind | split-window -h
/etc/tmux.conf: bind - split-window -v
/etc/tmux.conf: unbind '"'
/etc/tmux.conf: unbind %
/etc/tmux.conf:
/etc/tmux.conf: # moving between panes with vim movement keys
/etc/tmux.conf: bind h select-pane -L
/etc/tmux.conf: bind j select-pane -D
/etc/tmux.conf: bind k select-pane -U
/etc/tmux.conf: bind l select-pane -R
/etc/tmux.conf:
/etc/tmux.conf: # moving between windows with vim movement keys
/etc/tmux.conf: bind -r C-h select-window -t :-
/etc/tmux.conf: bind -r C-l select-window -t :+
/etc/tmux.conf:
/etc/tmux.conf: # resize panes with vim movement keys
/etc/tmux.conf: bind -r H resize-pane -L 5
/etc/tmux.conf: bind -r J resize-pane -D 5
/etc/tmux.conf: bind -r K resize-pane -U 5
/etc/tmux.conf: bind -r L resize-pane -R 5
/etc/tmux.conf:
/etc/tmux.conf: # I'm not hardcore enough for military time
/etc/tmux.conf: set-window-option -g clock-mode-style 12
/etc/tmux.conf:
/etc/tmux.conf: # reload tmux.conf
/etc/tmux.conf: bind r source-file /etc/tmux.conf \; display-message " ✱ ~/.tmux.conf is reloaded"
/etc/tmux.conf:
/etc/tmux.conf: # tmux is so slow by default (this allows for faster key repetition)
/etc/tmux.conf: set -sg escape-time 190
cmdq 0x6afde0: set-option -g prefix C-a (client -1)
cmdq 0x6afde0: bind-key C-a send-prefix (client -1)
cmdq 0x6afde0: unbind-key C-b (client -1)
cmdq 0x6afde0: set-option -gs escape-time 1 (client -1)
cmdq 0x6afde0: set-option -g base-index 1 (client -1)
cmdq 0x6afde0: set-window-option -g pane-base-index 1 (client -1)
cmdq 0x6afde0: set-window-option -g mode-mouse on (client -1)
cmdq 0x6afde0: set-option -g mouse-select-pane on (client -1)
cmdq 0x6afde0: set-option -g mouse-resize-pane on (client -1)
cmdq 0x6afde0: set-option -g mouse-select-window on (client -1)
cmdq 0x6afde0: set-window-option -g monitor-activity on (client -1)
cmdq 0x6afde0: set-option -g visual-activity on (client -1)
cmdq 0x6afde0: set-option -g mode-keys vi (client -1)
cmdq 0x6afde0: set-option -g history-limit 10000 (client -1)
cmdq 0x6afde0: bind-key Escape copy-mode (client -1)
cmdq 0x6afde0: unbind-key p (client -1)
cmdq 0x6afde0: bind-key p paste-buffer (client -1)
cmdq 0x6afde0: bind-key -t vi-copy v begin-selection (client -1)
cmdq 0x6afde0: bind-key -t vi-copy y copy-selection (client -1)
cmdq 0x6afde0: bind-key -t vi-copy Space halfpage-down (client -1)
cmdq 0x6afde0: bind-key -t vi-copy Bspace halfpage-up (client -1)
cmdq 0x6afde0: bind-key C-c run "tmux save-buffer - | xclip -i -sel clipboard" (client -1)
cmdq 0x6afde0: bind-key C-v run "tmux set-buffer "$(xclip -o -sel clipboard)"; tmux paste-buffer" (client -1)
cmdq 0x6afde0: bind-key | split-window -h (client -1)
cmdq 0x6afde0: bind-key - split-window -v (client -1)
cmdq 0x6afde0: unbind-key " (client -1)
cmdq 0x6afde0: unbind-key % (client -1)
cmdq 0x6afde0: bind-key h select-pane -L (client -1)
cmdq 0x6afde0: bind-key j select-pane -D (client -1)
cmdq 0x6afde0: bind-key k select-pane -U (client -1)
cmdq 0x6afde0: bind-key l select-pane -R (client -1)
cmdq 0x6afde0: bind-key -r C-h select-window -t :- (client -1)
cmdq 0x6afde0: bind-key -r C-l select-window -t :+ (client -1)
cmdq 0x6afde0: bind-key -r H resize-pane -L 5 (client -1)
cmdq 0x6afde0: bind-key -r J resize-pane -D 5 (client -1)
cmdq 0x6afde0: bind-key -r K resize-pane -U 5 (client -1)
cmdq 0x6afde0: bind-key -r L resize-pane -R 5 (client -1)
cmdq 0x6afde0: set-window-option -g clock-mode-style 12 (client -1)
cmdq 0x6afde0: bind-key r source-file /etc/tmux.conf ; display-message " ✱ ~/.tmux.conf is reloaded" (client -1)
cmdq 0x6afde0: set-option -gs escape-time 190 (client -1)
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 14 from client 8
got 6 from client 8
got 0 from client 8
cmdq 0x6af9d0: new-session (client 8)
new term: xterm-256color
xterm-256color override: colors 256
xterm-256color override: XT
xterm-256color override: Ms ]52;%p1%s;%p2%s
xterm-256color override: Cc ]12;%p1%s
xterm-256color override: Cr ]112
xterm-256color override: Cs [%p1%d q
xterm-256color override: Csr [2 q
new key Oo: 0x1021 (KP/)
new key Oj: 0x1022 (KP*)
new key Om: 0x1023 (KP-)
new key Ow: 0x1024 (KP7)
new key Ox: 0x1025 (KP8)
new key Oy: 0x1026 (KP9)
new key Ok: 0x1027 (KP+)
new key Ot: 0x1028 (KP4)
new key Ou: 0x1029 (KP5)
new key Ov: 0x102a (KP6)
new key Oq: 0x102b (KP1)
new key Or: 0x102c (KP2)
new key Os: 0x102d (KP3)
new key OM: 0x102e (KPEnter)
new key Op: 0x102f (KP0)
new key On: 0x1030 (KP.)
new key OA: 0x101d (Up)
new key OB: 0x101e (Down)
new key OC: 0x1020 (Right)
new key OD: 0x101f (Left)
new key [A: 0x101d (Up)
new key [B: 0x101e (Down)
new key [C: 0x1020 (Right)
new key [D: 0x101f (Left)
new key OH: 0x1018 (Home)
new key OF: 0x1019 (End)
new key [H: 0x1018 (Home)
new key [F: 0x1019 (End)
new key Oa: 0x501d (C-Up)
new key Ob: 0x501e (C-Down)
new key Oc: 0x5020 (C-Right)
new key Od: 0x501f (C-Left)
new key [a: 0x901d (S-Up)
new key [b: 0x901e (S-Down)
new key [c: 0x9020 (S-Right)
new key [d: 0x901f (S-Left)
new key [11^: 0x5002 (C-F1)
new key [12^: 0x5003 (C-F2)
new key [13^: 0x5004 (C-F3)
new key [14^: 0x5005 (C-F4)
new key [15^: 0x5006 (C-F5)
new key [17^: 0x5007 (C-F6)
new key [18^: 0x5008 (C-F7)
new key [19^: 0x5009 (C-F8)
new key [20^: 0x500a (C-F9)
new key [21^: 0x500b (C-F10)
new key [23^: 0x500c (C-F11)
new key [24^: 0x500d (C-F12)
new key [25^: 0x500e (C-F13)
new key [26^: 0x500f (C-F14)
new key [28^: 0x5010 (C-F15)
new key [29^: 0x5011 (C-F16)
new key [31^: 0x5012 (C-F17)
new key [32^: 0x5013 (C-F18)
new key [33^: 0x5014 (C-F19)
new key [34^: 0x5015 (C-F20)
new key [2^: 0x5016 (C-IC)
new key [3^: 0x5017 (C-DC)
new key [7^: 0x5018 (C-Home)
new key [8^: 0x5019 (C-End)
new key [6^: 0x501a (C-NPage)
new key [5^: 0x501b (C-PPage)
new key [11$: 0x9002 (S-F1)
new key [12$: 0x9003 (S-F2)
new key [13$: 0x9004 (S-F3)
new key [14$: 0x9005 (S-F4)
new key [15$: 0x9006 (S-F5)
new key [17$: 0x9007 (S-F6)
new key [18$: 0x9008 (S-F7)
new key [19$: 0x9009 (S-F8)
new key [20$: 0x900a (S-F9)
new key [21$: 0x900b (S-F10)
new key [23$: 0x900c (S-F11)
new key [24$: 0x900d (S-F12)
new key [25$: 0x900e (S-F13)
new key [26$: 0x900f (S-F14)
new key [28$: 0x9010 (S-F15)
new key [29$: 0x9011 (S-F16)
new key [31$: 0x9012 (S-F17)
new key [32$: 0x9013 (S-F18)
new key [33$: 0x9014 (S-F19)
new key [34$: 0x9015 (S-F20)
new key [2$: 0x9016 (S-IC)
new key [3$: 0x9017 (S-DC)
new key [7$: 0x9018 (S-Home)
new key [8$: 0x9019 (S-End)
new key [6$: 0x901a (S-NPage)
new key [5$: 0x901b (S-PPage)
new key [11@: 0xd002 (C-S-F1)
new key [12@: 0xd003 (C-S-F2)
new key [13@: 0xd004 (C-S-F3)
new key [14@: 0xd005 (C-S-F4)
new key [15@: 0xd006 (C-S-F5)
new key [17@: 0xd007 (C-S-F6)
new key [18@: 0xd008 (C-S-F7)
new key [19@: 0xd009 (C-S-F8)
new key [20@: 0xd00a (C-S-F9)
new key [21@: 0xd00b (C-S-F10)
new key [23@: 0xd00c (C-S-F11)
new key [24@: 0xd00d (C-S-F12)
new key [25@: 0xd00e (C-S-F13)
new key [26@: 0xd00f (C-S-F14)
new key [28@: 0xd010 (C-S-F15)
new key [29@: 0xd011 (C-S-F16)
new key [31@: 0xd012 (C-S-F17)
new key [32@: 0xd013 (C-S-F18)
new key [33@: 0xd014 (C-S-F19)
new key [34@: 0xd015 (C-S-F20)
new key [2@: 0xd016 (C-S-IC)
new key [3@: 0xd017 (C-S-DC)
new key [7@: 0xd018 (C-S-Home)
new key [8@: 0xd019 (C-S-End)
new key [6@: 0xd01a (C-S-NPage)
new key [5@: 0xd01b (C-S-PPage)
new key [I: 0x1031 ((null))
new key [O: 0x1032 ((null))
new key OP: 0x1002 (F1)
new key OQ: 0x1003 (F2)
new key OR: 0x1004 (F3)
new key OS: 0x1005 (F4)
new key [15~: 0x1006 (F5)
new key [17~: 0x1007 (F6)
new key [18~: 0x1008 (F7)
new key [19~: 0x1009 (F8)
new key [20~: 0x100a (F9)
new key [21~: 0x100b (F10)
new key [23~: 0x100c (F11)
new key [24~: 0x100d (F12)
new key [1;2P: 0x100e (F13)
new key [1;2Q: 0x100f (F14)
new key [1;2R: 0x1010 (F15)
new key [1;2S: 0x1011 (F16)
new key [15;2~: 0x1012 (F17)
new key [17;2~: 0x1013 (F18)
new key [18;2~: 0x1014 (F19)
new key [19;2~: 0x1015 (F20)
new key [2~: 0x1016 (IC)
new key [3~: 0x1017 (DC)
replacing key OH: 0x1018 (Home)
replacing key OF: 0x1019 (End)
new key [6~: 0x101a (NPage)
new key [5~: 0x101b (PPage)
new key [Z: 0x101c (BTab)
replacing key OA: 0x101d (Up)
replacing key OB: 0x101e (Down)
replacing key OD: 0x101f (Left)
replacing key OC: 0x1020 (Right)
new key [3;2~: 0x9017 (S-DC)
new key [3;3~: 0x3017 (M-DC)
new key [3;4~: 0xb017 (M-S-DC)
new key [3;5~: 0x5017 (C-DC)
new key [3;6~: 0xd017 (C-S-DC)
new key [3;7~: 0x7017 (C-M-DC)
new key [1;2B: 0x901e (S-Down)
new key [1;3B: 0x301e (M-Down)
new key [1;4B: 0xb01e (M-S-Down)
new key [1;5B: 0x501e (C-Down)
new key [1;6B: 0xd01e (C-S-Down)
new key [1;7B: 0x701e (C-M-Down)
new key [1;2F: 0x9019 (S-End)
new key [1;3F: 0x3019 (M-End)
new key [1;4F: 0xb019 (M-S-End)
new key [1;5F: 0x5019 (C-End)
new key [1;6F: 0xd019 (C-S-End)
new key [1;7F: 0x7019 (C-M-End)
new key [1;2H: 0x9018 (S-Home)
new key [1;3H: 0x3018 (M-Home)
new key [1;4H: 0xb018 (M-S-Home)
new key [1;5H: 0x5018 (C-Home)
new key [1;6H: 0xd018 (C-S-Home)
new key [1;7H: 0x7018 (C-M-Home)
new key [2;2~: 0x9016 (S-IC)
new key [2;3~: 0x3016 (M-IC)
new key [2;4~: 0xb016 (M-S-IC)
new key [2;5~: 0x5016 (C-IC)
new key [2;6~: 0xd016 (C-S-IC)
new key [2;7~: 0x7016 (C-M-IC)
new key [1;2D: 0x901f (S-Left)
new key [1;3D: 0x301f (M-Left)
new key [1;4D: 0xb01f (M-S-Left)
new key [1;5D: 0x501f (C-Left)
new key [1;6D: 0xd01f (C-S-Left)
new key [1;7D: 0x701f (C-M-Left)
new key [6;2~: 0x901a (S-NPage)
new key [6;3~: 0x301a (M-NPage)
new key [6;4~: 0xb01a (M-S-NPage)
new key [6;5~: 0x501a (C-NPage)
new key [6;6~: 0xd01a (C-S-NPage)
new key [6;7~: 0x701a (C-M-NPage)
new key [5;2~: 0x901b (S-PPage)
new key [5;3~: 0x301b (M-PPage)
new key [5;4~: 0xb01b (M-S-PPage)
new key [5;5~: 0x501b (C-PPage)
new key [5;6~: 0xd01b (C-S-PPage)
new key [5;7~: 0x701b (C-M-PPage)
new key [1;2C: 0x9020 (S-Right)
new key [1;3C: 0x3020 (M-Right)
new key [1;4C: 0xb020 (M-S-Right)
new key [1;5C: 0x5020 (C-Right)
new key [1;6C: 0xd020 (C-S-Right)
new key [1;7C: 0x7020 (C-M-Right)
new key [1;2A: 0x901d (S-Up)
new key [1;3A: 0x301d (M-Up)
new key [1;4A: 0xb01d (M-S-Up)
new key [1;5A: 0x501d (C-Up)
new key [1;6A: 0xd01d (C-S-Up)
new key [1;7A: 0x701d (C-M-Up)
spawn: /bin/bash --
session 0 destroyed
writing 18 to client 8
writing 3 to client 8
lost client 8
此日志中的一些内容来自我的.tmux.conf
.
有任何想法吗?
编辑#1
阅读@jasonwryan 的答案后,我通读了Sourceforge 页面对于 tmux 并了解 TERM 环境设置是一个潜在问题。
我当前的 $TERM 值如下:
$ echo $TERM
xterm-256color
我尝试运行以下命令来尝试更改它。
$ export TERM=screen
$ tmux
$ echo $TERM
screen
获得与之前相同的结果后,我将 $TERM 值重新导出到xterm-256color
.
编辑#2
tmux
以 root 用户身份运行会话工作正常;但是,tmux
以任何特权用户身份使用总是会导致上述问题。
答案1
我在 CentOS 7 和捆绑的 tmux 二进制文件中也遇到了这个问题。结果我必须将我的用户放入 tty 组:
# /etc/group
tty:x:5:<username>
即使我的 ptmx 权限看起来像这样,我也必须这样做:
crw-rw-rw- 1 root tty 5, 2 Dec 9 23:17 /dev/ptmx
答案2
关于设置等的各种评论TERM
似乎并没有解决实际问题。
最可能的解释是有问题权限这可以防止tmux
打开伪终端连接。例如,某人可能做了chmod
或chown
破坏了程序。您可以通过查看结果来了解情况是否如此strace
,例如,
TERM=xterm-256color script -c "strace -fo strace.out -s 2048 tmux -v"
19603 open("/tmp/tmux-1001/default.lock", O_WRONLY|O_CREAT, 0600) = 6
19603 open("tmux-client-19603.log", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 6
19603 open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 8
19603 sendmsg(7, {msg_name(0)=NULL, msg_iov(43)=[{"\16\0\0\0\20\4\0\0\7\0\0\0\377\377\377\377TERM=xterm-256color\0008\177\0\0o\356\343\3738\177\0\0\201bP\217\3\200\377\377\17>
19605 open("/dev/null", O_RDWR) = 7
19605 open("tmux-server-19605.log", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 7
19605 open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 9
19605 open("/users/tom/.tmux.conf", O_RDONLY) = 6
19605 open("/usr/share/terminfo/x/xterm-256color", O_RDONLY) = 10
19605 open("/dev/ptmx", O_RDWR) = 10
19605 open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 11
19605 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 11
19605 open("/lib64/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 11
19605 open("/etc/group", O_RDONLY|O_CLOEXEC) = 11
19605 open("/dev/pts/2", O_RDWR|O_NOCTTY) = 11
19605 open("/proc/0/cmdline", O_RDONLY) = -1 ENOENT (No such file or directory)
19605 open("/proc/0/cmdline", O_RDONLY) = -1 ENOENT (No such file or directory)
19605 open("/proc/0/cmdline", O_RDONLY) = -1 ENOENT (No such file or directory)
“/dev/ptmx”master 或“/dev/pts/”失败xx”奴隶会停下来tmux
。
服务器日志显示它在生成进程后立即死亡,在源代码中这是它开始打开伪终端的点,例如(引用window.c
tmux 1.8 中的内容):
log_debug("spawn: %s -- %s", wp->shell, wp->cmd);
memset(&ws, 0, sizeof ws);
ws.ws_col = screen_size_x(&wp->base);
ws.ws_row = screen_size_y(&wp->base);
switch (wp->pid = forkpty(&wp->fd, wp->tty, NULL, &ws)) {
case -1:
wp->fd = -1;
xasprintf(cause, "%s: %s", cmd, strerror(errno));
return (-1);
以下服务器消息来自session_destroy
(引用自session.c
):
/* Destroy a session. */
void
session_destroy(struct session *s)
{
struct winlink *wl;
log_debug("session %s destroyed", s->name);
RB_REMOVE(sessions, &sessions, s);
notify_session_closed(s);
从以下函数中调用server.c
:
/* Signal handler. */
void
server_signal_callback(int sig, unused short events, unused void *data)
{
switch (sig) {
case SIGTERM:
server_shutdown = 1;
server_send_shutdown();
break;
case SIGCHLD:
server_child_signal();
break;
case SIGUSR1:
event_del(&server_ev_accept);
close(server_fd);
server_fd = server_create_socket();
server_add_accept(0);
break;
}
}
当您运行时strace
,您可以看到正在处理哪个信号。
意外字符来自由 完成的正常初始化tmux
。其中一部分使用“\033[c”询问终端它是什么类型(请参阅XTerm 控制序列对此进行解释)。在正常初始化中,tmux
发送几个转义序列。这个请求需要响应,当响应到来时,它tmux
不再监听它,它只是在你的 shell 上回响。
对于普通 VT100,您会得到该特定响应。
对于它的价值,这是初始化的可见渲染,其中\E
是\033
:
Script started on Sun Jun 26 06:16:07 2016
\n
\E[?1049h
\E(B
\E[m
\E[?1l
\E>
\E[H
\E[2J
\E[?12l
\E[?25h
\E[?1000l
\E[?1006l
\E[?1005l
\E[c
\E[>4;1m
\E[?1004h
\E]112^G
\E[?25l
\E[1;1H
\E[K\r
答案3
在 mac 上也有同样的问题。问题来自剪贴板配置行:
set-option -g default-command "reattach-to-user-namespace -l zsh"
通过在终端中运行解决了该问题:
brew install reattach-to-user-namespace
答案4
我的问题是 /dev/ptmx 文件 (0600) 的权限错误。当我将其更改为 0666(如 man ptmx 中提到的那样)时,tmux 启动没有问题。