Environment-Variables
為 su 設置根 PATH
當我(在我的 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
在
/etc/login.defs
我有(也是預設的東西):ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
為什麼我的 PATH 設置不正確
su
?
當被要求保護環境時,Modern
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.