【问题标题】:linux-mint non-interactive shell start up fileslinux-mint 非交互式 shell 启动文件
【发布时间】:2016-11-30 00:08:10
【问题描述】:

在 Linux-Mint 18 中,启动非交互式 shell 时会读取哪些文件?

我正在尝试通过 ssh 执行命令,例如 ssh norio@remote.host.net coolcommand 但我得到一个错误 bash: coolcommand: command not found 文件coolcommand 位于/home/norio/bin/,并且 我将PATH 环境变量设置为包含此目录 在/home/norio/.bashrc 中,这个.bashrc 设置为来自/home/norio/.profile/home/norio/.bash_profile。 但是,当远程非交互式 shell 启动时,似乎没有读取任何这些文件。事实上,/etc/profile 似乎没有提供任何这些文件。我需要编辑这个文件吗?或者,有没有其他方法可以为非root用户设置非交互式shell的启动过程?

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

【问题讨论】:

  • 有趣的事实:coolcommand 不是 bash,因此它与 ~/.bashrc 或任何 bash 相关文件无关。
  • @IporSircer 那么哪个shell处理ssh传递的远程命令?
  • 如果不指定任何命令,默认情况下 sshd 在登录后运行bash。如果您指定一个命令,则 sshd 运行它而不是 bash 或任何其他shell 或任何其他程序。你得到你想要的:运行coolcommand
  • @IporSircer 当我执行ssh remote.host.net ls 时,程序ls 在没有任何shell 干预的情况下运行? sshd如何知道ls的路径?
  • @IporSircer OpenSSH 服务器使用用户的登录 shell 启动远程命令(由客户端请求)作为 shell 命令。例如。如果用户的 shell 是 bash,则服务器启动相当于 bash -c 'the-command'

标签: linux bash shell ssh linux-mint


【解决方案1】:

来自documentation

Bash 尝试确定它何时在其标准输入连接到网络连接的情况下运行,就像由远程 shell 守护程序(通常是 rshd)或安全 shell 守护程序 sshd 执行时一样。如果 Bash 确定它正在以这种方式运行,它会从 ~/.bashrc 读取并执行命令,如果该文件存在并且是可读的。如果作为 sh 调用,它将不会执行此操作。 --norc 选项可用于禁止此行为,--rcfile 选项可用于强制读取另一个文件,但 rshd 和 sshd 通常都不会使用这些选项调用 shell 或允许指定它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 2022-07-14
    • 2017-06-17
    • 2016-02-17
    • 2011-08-29
    • 1970-01-01
    • 2013-02-03
    相关资源
    最近更新 更多