use*_*209 6 root su path environment-variables
当我(在我的 debian 机器上)使用 更改为 root 用户时su
,显然 PATH 设置不正确。一些重要的目录如usr/local/sbin
丢失。
在/etc/profile
我有以下几行(显然不是我写的标准默认内容):
if [ "`id -u`" -eq 0]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin"
fi
export PATH
Run Code Online (Sandbox Code Playgroud)
在/etc/login.defs
我有(也是默认的东西):
ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Run Code Online (Sandbox Code Playgroud)
为什么我的 PATH 设置不正确su
?
小智 7
当被要求保护环境时,现代su
不再PATH
从调用者那里重置;如果您需要执行此操作su --login
。
来自/usr/share/doc/util-linux/NEWS.Debian.gz
:
- new 'su' (with no args, i.e. when preserving the environment) also
preserves PATH and IFS, while old su would always reset PATH and IFS
even in 'preserve environment' mode.
...
The first difference is probably the most user visible one. Doing
plain 'su' is a really bad idea for many reasons, so using 'su -' is
strongly recommended to always get a newly set up environment similar
to a normal login. If you want to restore behaviour more similar to
the previous one you can add 'ALWAYS_SET_PATH yes' in /etc/login.defs.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11404 次 |
最近记录: |