4

I want to be able to run a sudo command inside of a bash script but I was wondering what if I want any user in my server to be able to execute the script without to provide them with my root password, is this possible?

  • You'd want to configure sudo to allow any user to execute the command that you want them to be able to execute via the shell script (without a password). Then if the user runs the script, the script will run sudo as that user, and sudo will validate the execution of the command. – Andy Dalton Sep 14 '15 at 19:07
7

Try to define it in the sudo configuration (/etc/sudoers) for your script:

ortega ALL=(ALL) NOPASSWD: /path-to-your-script
  • Thanks for your response Marco but I can't get it to work: I get this error when I try to execute it as a normal user: ls: cannot open directory /var/lib/php5: Permission denied This is what I put in sudoers file: ALL ALL=(ALL) NOPASSWD: /home/user/asd.sh and these are the permissions of the file: -rwxr-xr-x 1 user user 20 Sep 14 16:02 asd.sh – VaTo Sep 14 '15 at 22:15
  • 2
    Did you sudo the script? Or just type the scripts name? – Canadian Luke Sep 14 '15 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.