Marco Falzone Marco Falzone - 9 months ago 43
Bash Question

Execute root command with no root user avoiding password prompt

I have a 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/
marco ALL=(ALL) ALL

Any clue?
Thank you.


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