Sudo

HGRCPATH 保存在 /etc/sudoers 中,但被 hg 忽略?

  • August 11, 2013

我正在嘗試按照“sudo 和多個使用者”下的說明進行操作。我相信我設法進行了/etc/sudoers足夠正確的修改(通過Defaults :me env_keep += "HGRCPATH"在預設部分的開頭添加,但後來:me因為 sudo 給我解析錯誤而刪減),因為我得到了這個:

[me /]$ su
Password:
[root /]$ echo $HGRCPATH
/home/me/.hgrc

但是,當我嘗試實際使用時hg,我遇到了麻煩:

[me /]$ sudo hg commit -m "Initial check-in."
abort: no username supplied (see "hg help config")

確實:

[me /]$ sudo hg debugconfig --debug | grep read
read config from: /usr/etc/mercurial/hgrc
read config from: /etc/mercurial/hgrc
read config from: /etc/mercurial/hgrc.d/mergetools.rc
read config from: /root/.hgrc

為什麼hg似乎忽略 $HGRCPATH 並查看/root/.hgrc而不是/home/me/.hgrc

更新

以下是未註釋的行/etc/sudoers

$ sudo cat /etc/sudoers | grep '^[^#]'
Defaults env_keep += "HGRCPATH"
Defaults    requiretty
Defaults   !visiblepw
Defaults    always_set_home
Defaults    env_reset
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults    env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults    env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults    env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults    env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
root    ALL=(ALL)       ALL
me     ALL=(ALL)       ALL
Defaults env_keep += "HGRCPATH"
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"

第二行重置env_keep。在任何行之前堅持+=或移動該行。=``+=

引用自:https://unix.stackexchange.com/questions/86283