【发布时间】: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