I have a script.sh file executing the following command:
chown -R apache:apache /var/www/html/my/data
If i try to execute with a non-root user (username = marco), the prompt password halts the script waiting for the input.
I’m trying to configure the /etc/sudoers file adding the following lines, but with none of them works and I’m always prompted for sudo password:
marco ALL=(ALL:ALL) NOPASSWD:/my/directory/structure/script.sh marco ALL=(ALL) ALL
Any clue? Thank you.
Advertisement
Answer
If you only need root permission to run chown, then there is no need to give the whole script root permissions. Place in the script:
sudo chown -R apache:apache /var/www/html/my/data
And, using sudoedit, add the line:
marco ALL=(ALL:ALL) NOPASSWD:chown -R apache:apache /var/www/html/my/data