macos tmux 不重新连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9039256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:48:35  来源:igfitidea点击:

tmux not re-attaching

macoszshputtytmuxiterm

提问by kenny

I recently switched from using screen to tmux (obtained through macports), as I like the feature set more. However, I can't seem to get tmux to reattach from an alternate location, like I can screen.

我最近从使用 screen 切换到 tmux(通过 macports 获得),因为我更喜欢这个功能集。但是,我似乎无法让 tmux 从备用位置重新连接,就像我可以筛选一样。

At home on my mac, I will open up iTerm2, my default shell is zsh, and I will begin a tmux session with tmux. I get all my spits set up, ssh'd into the proper servers, etc., and work for a while. Time to go to work. <C-a> d- tmux detaches.

在家里的 Mac 上,我将打开 iTerm2,我的默认 shell 是 zsh,然后我将使用tmux. 我把所有的信息都设置好了,ssh 连接到了合适的服务器等等,然后工作了一段时间。该上班了。<C-a> d- tmux 分离。

I get to work, where I use a windows xp machine. I fire up putty, ssh into my mac back at home, attempt a tmux attach, and get an error message:

我开始工作,在那里我使用 windows xp 机器。我启动 putty,回到家里的 mac 上,尝试 a tmux attach,并收到一条错误消息:

no sessions

no sessions

I cannot seem to determine why this would happen. I am not afraid to dig into this, but don't even know where to start. Thoughts?

我似乎无法确定为什么会发生这种情况。我并不害怕深入研究,但甚至不知道从哪里开始。想法?

P.S. I have already removed my .tmux.conf file, so it's using the default config.

PS 我已经删除了我的 .tmux.conf 文件,所以它使用默认配置。

采纳答案by Chris Johnsen

tmuxstores its server socket in a directory under the directory specified by the TMPDIR environment variable.

tmux将其服务器套接字存储在 TMPDIR 环境变量指定的目录下的目录中。

In your GUI session you probably end up with a TMPDIR that points to somewhere under /var(e.g. /var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/).

在您的 GUI 会话中,您可能最终会得到一个 TMPDIR,该 TMPDIR 指向/var(例如/var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/)下某处。

When you are logged in through SSH, you probably end up without a TMPDIR set, so tmuxlooks under /tmp/for its socket.

当您通过 SSH 登录时,您可能最终没有设置 TMPDIR,因此tmux 会查找/tmp/其套接字。

On a 10.6 system, here is my TMPDIR with zsh/Terminal, and with zsh/SSH:

在10.6的系统,这里是我的TMPDIR与zsh的/终端,并与zsh的/ SSH:

% echo local: ${TMPDIR-unset}; ssh localhost 'echo remote: ${TMPDIR-unset}'
local: /var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/
remote: unset

If you know the value you need to use for TMPDIR, you can specify it when attaching (or running some other tmuxcommand outside of the session itself):

如果您知道需要用于 TMPDIR 的值,则可以在附加(或在会话本身之外运行其他一些tmux命令)时指定它:

TMPDIR=/var/folders/mV/mVip4IQ4EXOriTiLJmeSuk+++Tc/-Tmp-/ tmux attach

If you do not know the directory your GUI session was using you might be able to find it with something like this (the syntax is specific to zsh; it searches under /var/folders/for a directory named -Tmp-that is owned by the current user):

如果您不知道您的 GUI 会话正在使用的目录,您可能可以通过以下方式找到它(语法特定于zsh;它会在当前用户拥有的/var/folders/名为的目录下搜索-Tmp-):

echo /var/folders/**/*/-Tmp-(U/)

To avoid problems in the future, you might want to unset TMPDIR before starting your server (or set it to something that you can more easily predict).

为避免将来出现问题,您可能希望在启动服务器之前取消设置 TMPDIR(或将其设置为您更容易预测的内容)。

回答by Dan Abramov

In my case, apparently temp folder was cleaned.
This blog posthelped me recover my “lost” session:

就我而言,显然临时文件夹已被清理。
这篇博文帮助我恢复了“丢失”的会话:

I finally got the solution: sending the signal 10 forced tmux to recreate sockets. After that I could run tmux again without losing my session:

$ killall -10 tmux

我终于得到了解决方案:发送信号 10 强制 tmux 重新创建套接字。之后我可以再次运行 tmux 而不会丢失我的会话:

$ killall -10 tmux

回答by Tyler Holien

The -Uoption of lsoflists open socket files, so lsof -U | grep '^tmux'will list all of the sockets in use by tmux. If you're not logged in as the same user that started tmux, you will need to use sudo.

列出打开套接字文件的-U选项lsof,因此lsof -U | grep '^tmux'将列出tmux使用的所有套接字。如果您不是以启动tmux的同一用户身份登录,则需要使用sudo.

The last column of each row is the name of the file. The files you care about start with a /.

每行的最后一列是文件名。您关心的文件以/.

The rows you're looking for will look something like this:

您要查找的行将如下所示:

tmux 1234  username 6u unix 0xffffffabcd123456 0t0 /private/var/folders/M8/M8tFwolmH08fOvJ+-35VI++++TM/-Tmp-/tmux-502/default
tmux 56789 username 6u unix 0xffffff123456789a 0t0 /private/tmp/tmux-502/default

回答by jps3

I have a variation on the lsofsuggestion that I have been using with some success to “recover” the TMPDIR variable which can help working around a bunch of annoyances. The advantage, I suppose, is that one can be a little more exacting about what lsofreturns and easier to parse out the correct value (on the off-chance at some point some atypical chars, but still valid, ever output).

我对lsof我一直在使用并成功“恢复”TMPDIR 变量的建议有一个变体,这可以帮助解决一堆烦恼。我想,优点是可以对lsof返回的内容更加严格,并且更容易解析出正确的值(在某些时候,某些非典型字符的偶然机会,但仍然有效,永远输出)。

A quick, one-liner is:

一个快速的单行是:

$ lsof -Fn -d6 -aUc tmux | grep ^n | cut -c2-
/private/var/folders/_l/f_n8blps05xfnkw6fs3dcn_80000gp/T/tmux-502/default

I use the following script (could also be a function in ~/.bash_profile or other appropriate place I suppose):

我使用以下脚本(也可以是 ~/.bash_profile 或我想其他适当位置中的函数):

#!/bin/bash

if [[ -z "${TMPDIR}" ]]; then
  while read line; do
      case $line in
      n*) line="${line#n}"
          export TMPDIR="${line%%/tmux-$(id -u)/*}"
          ;;
      esac;
  done < <(lsof -Fn -d6 -aUc tmux)
else
    echo ">> $TMPDIR already defined: $TMPDIR" 1>&2
fi

https://gist.github.com/jps3/769d50a6a7611949473b

https://gist.github.com/jps3/769d50a6a7611949473b