为什么 screen 会导致 sftp 出现问题?

为什么 screen 会导致 sftp 出现问题?

我喜欢使用 screen,但我在 ssh 上使用它的经验并不多。最近,我在工作中获得了 shell 帐户,我决定尝试配置它,以便在登录时运行 screen。我正在使用 putty 通过 ssh 远程登录。

无论如何,我有两种方法似乎都很有效:

  1. 配置 putty 在连接时运行 /usr/bin/screen -R,
  2. 将此行添加到我的.bashrc中:if [ -z "$STY" ]; then /usr/bin/screen -R; fi

问题是,后来我尝试 scp 一些文件时,却无法连接。它说“必须连接到终端”。我还尝试了 Filezilla,但出现了严重的连接问题。我谷歌了一下,显然我不是第一个因为尝试使用 screen 作为登录 shell 而导致 sftp 出错的人。http://winscp.net/forum/viewtopic.php?t=1715

我想知道是否有人可以提供一些关于为什么会发生这种情况的见解,因为我真的不知道并且我有兴趣了解它并可能找到解决方法。

答案1

您应该将与登录 shell 相关的所有内容放入 中~/.bash_profile,将与交互式(非登录)shell 相关的内容放入 中~/.bashrc。摘自 bash(1) 手册页:

   ~/.bash_profile
          The personal initialization file, executed for login shells
   ~/.bashrc
          The individual per-interactive-shell startup file

因此,您不应该只是进行符号链接~/.bashrc~/.bash_profile或反之亦然),而应该拥有两个包含略有不同的内容的独立文件。

输入[ -z "$STY" ] && then /usr/bin/screen -Ronly ~/.bash_profile,然后您只会在实际登录时运行屏幕,而不是每次生成交互式 shell 时都运行屏幕(我现在手头没有 scp 源,但依稀记得它实际上生成了一个 shell,以便 shell 生成了进程~/.bashrc)。

相关内容