
/etc/sudoers
명령을 통해 다음 한 줄을 추가했습니다 visudo
.
www-data ALL=(ALL) NOPASSWD: /var/www/db_backup.sh
다음을 통해 명령을 실행하면 www-data
:
sudo -u www-data /var/www/db_backup.sh
다음 메시지를 받았습니다.
sudo: unable to execute /var/www/db_backup.sh: Permission denied
과거에도 이와 동일한 절차를 문제 없이 사용했기 때문에 이것이 왜 발생하는지 잘 모르겠습니다. 내가 간과하고 있는 것이 분명 있을 것이다. 누구에게나 지적하는 것이 있습니까? 내 /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"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
www-data ALL=(ALL) NOPASSWD: /var/www/db_backup.sh
# 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
또한 www-data에서 실행되는 PHP 프로세스 내에서 명령을 실행하려고 하면 sudo /var/www/db_backup.sh
다음 메시지가 수신됩니다(비록 sudoers 파일에서 권한이 선택되지 않는 문제에서 발생하는 것으로 수집했지만).
sudo: no tty present and no askpass program specified
편집하다
ls -al /var/www/db_backup.sh
다음과 같은 결과가 나옵니다:
-rwxrwx--- 1 root root 523 Jan 7 2019 /var/www/db_backup.sh
답변1
설명에 언급된 대로 다른 사용자는 스크립트를 실행할 수 없습니다. 따라서 언급한 대로 사용자 소유권과 그룹 소유권을 변경한 다음 실행 파일로 표시하십시오 chown www-data:www-data /var/www/db_backup.sh && chmod +x /var/www/db_backup.sh
. 두 번째 문제는 별도로 물어봐야 하는데, 어쨌든 스크립트에 어떤 내용이 담겨 있는지 정확히 알지 못해 무엇이 문제인지 알기 어렵습니다.