Answers:
通常由中的secure_path
选项设置/etc/sudoers
。来自man sudoers
:
secure_path Path used for every command run from sudo. If you don't
trust the people running sudo to have a sane PATH environ‐
ment variable you may want to use this. Another use is if
you want to have the “root path” be separate from the “user
path”. Users in the group specified by the exempt_group
option are not affected by secure_path. This option is not
set by default.
要运行非默认命令$PATH
,您可以
使用完整路径:sudo ~/bin/my-command
; 要么
将包含命令的目录添加到secure_path
。运行sudo visudo
并编辑安全路径行:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/youruser/bin/"
保存文件,下次运行时sudo
,该目录~/bin
将位于其中$PATH
。