我遇到以下错误,试图在运行时允许某些环境变量传递给新环境sudo
:
sudo: sorry, you are not allowed to preserve the environment
一些可能有助于调试的信息:
[deploy@worker1 ~]$ sudo -l
Matching Defaults entries for deploy on this host:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET
XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin, env_keep+="GIT_WORK_TREE GIT_DIR", !requiretty
User deploy may run the following commands on this host:
(ALL) NOPASSWD: /usr/bin/git, (ALL) /etc/init.d/httpd*, (ALL) /sbin/service, (ALL) /usr/bin/make, (ALL) /bin/echo
我正在运行的示例:
[deploy@worker1 ~]$ export GIT_DIR="/home/ashinn/testing"
[deploy@worker1 ~]$ sudo -E sh -c 'echo "$GIT_DIR"'
sudo: sorry, you are not allowed to preserve the environment
我的sudoers.d文件用于此特定配置:
Defaults:deploy env_keep += "GIT_WORK_TREE GIT_DIR", !requiretty
deploy ALL=(ALL) NOPASSWD: /usr/bin/git, /etc/init.d/httpd*, /sbin/service, /usr/bin/make, /bin/echo
我也尝试添加!env_reset
到默认值,但仍然失败,并出现相同的错误。我觉得我可能缺少一些明显的东西,需要重新审视。我在这里想念什么?
sudo
(option(s))
echo $GIT_DIR
sudo
$GIT_DIR
sudo
sudo printenv GIT_DIR
sudo env | grep GIT_DIR
sudo sh -c 'echo "$GIT_DIR"'