/etc/sudoers에 설정한 비밀번호 없는 프롬프트가 작동하지 않는 이유는 무엇입니까? [복사]

/etc/sudoers에 설정한 비밀번호 없는 프롬프트가 작동하지 않는 이유는 무엇입니까? [복사]

내 sudo 버전은

$ sudo --version
Sudo version 1.8.16
Sudoers policy plugin version 1.8.16
Sudoers file grammar version 45
Sudoers I/O plugin version 1.8.16

$ which sudo
/usr/bin/sudo

$ whereis sudo
sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gz

/etc/sudoers줄 뒤에 줄을 추가했습니다root:

# User privilege specification
root    ALL=(ALL:ALL) ALL
# my change for scaling down cpu freq
t       ALL=(ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh

하지만 Ubuntu 16.04를 다시 시작한 후에도 스크립트를 실행할 때 여전히 비밀번호를 제공해야 했습니다 sudo.

$ sudo /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh  1600000
[sudo] password for t: 

이유를 알고 싶습니다.

참고 하시기 /etc/sudoers바랍니다

  • root과 사이의 구분 기호 는 탭이고 합계도 탭 으로 ALL구분했으며 다른 구분 기호는 공백이라는 것을 알았습니다 . 원래는 몇 개의 공백을 두고 별도로 만들었지 만 작동하지 않았습니다. 구분 기호가 중요합니까?tALLtALL

  • /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh은 심볼릭 링크가 없는 경로 이름입니다. 처음에는 심볼릭 링크를 시도했지만 작동하지 않았습니다. 심볼릭 링크가 중요한가 아닌가?

감사해요.


고쳐 쓰다:

Steve의 답변에서 제안한 대로 줄을 /etc/sudoers다음으로 변경했습니다.

t       ALL=(ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh *

마지막에 추가했지만 *작동하지 않습니다.

지금 내 /etc/sudoers모습

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
# my change for scaling down cpu freq
# t     ALL=(ALL:ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh *
t ALL=(ALL:ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh *

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

그룹에는 ( ? 와 함께 ) 및 다음이 t포함됩니다 .admadmadminsudo

$ groups t
t : t adm cdrom sudo dip plugdev lpadmin sambashare

실행이 허용되는 명령은 t다음과 같습니다.

$ sudo -l
Matching Defaults entries for t on ocean:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User t may run the following commands on ocean:
    (ALL : ALL) NOPASSWD:
        /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh *
    (ALL : ALL) ALL

답변1

@steve가 언급한 매개변수 외에도 ALL=(ALL)for를 ALL=(ALL:ALL)다음과 같이 변경합니다.

t ALL=(ALL:ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh *

사용자 t가 sudo 또는 admin 그룹에 속하는 경우 이 줄도 변경해야 합니다.뒤쪽에admin 및 sudo 그룹에 대한 일반 규칙. Per man sudoers, 조건을 고려한 마지막 줄이 승리합니다.

여러 항목이 사용자와 일치하면 순차적으로 적용됩니다.
일치하는 항목이 여러 개인 경우 마지막 항목이 사용됩니다(가장 구체적인 항목일 필요는 없음).

따라서 이제 마지막 줄이 더 엄격한 조건을 충족하면 NOPASSWD 지시문이 적용되고 비밀번호를 다시 묻지 않습니다.

답변2

어쩌면 논쟁을 전달한다는 사실이 문제를 일으키는 것일 수도 있습니다.

바꾸다:

t       ALL=(ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh

이 시도:

t       ALL=(ALL) NOPASSWD: /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh *

관련 정보