`/etc/sudoers` -- 하나의 명령에만 `env_keep`을 지정하시겠습니까?

`/etc/sudoers` -- 하나의 명령에만 `env_keep`을 지정하시겠습니까?

sudo특정 환경 변수가 지정된 명령에 대해서만 유지되도록 지정하는 방법이 있습니까 ? 어떤 목적을 위해 나는 내 $HOME환경을 원합니다. 특정 명령을 실행할 때 변수가 유지됩니다. 다른 목적이나 다른 명령을 위해 재설정하고 싶습니다. 이것이 가능합니까 /etc/sudoers?

편집하다:

답변 주셔서 감사합니다. 나는 "그렇다면 왜 이것이 작동하지 않는가?"라는 후속 질문을 할 수 있는지 궁금했습니다.

시작하려는 예에서 다음을 사용하면 sudo nano$HOME/.nanorc.

Defaults:simon env_keep=HOME

완벽하게 작동합니다. 내가 이것을 사용하는 경우 :

Defaults!/bin/nano env_keep=HOME

아니면 이거:

Cmnd_Alias      NANO = /usr/bin/nano,/bin/nano,/bin/rnano
Defaults!NANO   env_keep=HOME

전혀 작동하지 않습니다. 이유에 대한 제안이 있으십니까? (그런데 데비안에서 테스트 중입니다.)

(참고: 이것이 구체적이라고 생각하지는 않습니다. btw - nano간단한 한 줄 bash 스크립트로 동작을 재현할 수 있습니다).echo$HOME

답변1

env_keep/path/to/command(모든 사용자가 규칙을 통해 호출하는 경우) 및 사용자 joe(실행 중인 명령에 관계없이) 만 재정의합니다 .

Defaults!/path/to/command env_keep=HOME
Defaults:joe env_keep=HOME

-=또는 를 사용하여 목록 +=에서 항목을 제거하거나 추가 할 수 있습니다 .env_keep

답변2

Cmnd_Alias      PBUILDER = /usr/sbin/pbuilder,/usr/sbin/cowbuilder
Defaults!PBUILDER       env_keep+=HOME

이 줄은 사용자 프로필을 찾는데 루트로 실행해야 하는 문제를 해결하기 위해 작성한 것입니다 /etc/sudoers(이를 이동하면 시스템 프로필과 사용자 프로필을 모두 갖는 목적이 무산됩니다).pbuilder$HOME/root

답변3

남자 수도:

   env_reset       If set, sudo will reset the environment to only contain
                   the LOGNAME, SHELL, USER, USERNAME and the SUDO_*
                   variables.  Any variables in the caller’s environment
                   that match the env_keep and env_check lists are then
                   added.  The default contents of the env_keep and
                   env_check lists are displayed when sudo is run by root
                   with the -V option.  If the secure_path option is set,
                   its value will be used for the PATH environment
                   variable.  This flag is on by default.

그렇습니다. /etc/sudoers.conf에서 env_reset, 및 를 사용하여 env_keep이 작업을 수행 할 수 있습니다.env_check

관련 정보