Marco Falzone Marco Falzone - 1 year ago 117
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download