Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 yesterday

1 Answer 1

up vote 5 down vote accepted

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

ortega ALL=(ALL) NOPASSWD: /path-to-your-script
share|improve this answer
2  
Any user, not just ortega –  roaima yesterday
2  
Just replace by ortega with ALL and it should work for all users. –  Marco yesterday
    
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 –  Saul Ortega yesterday
2  
Did you sudo the script? Or just type the scripts name? –  Canadian Luke yesterday
    
I didn't, Thanks @CanadianLuke! that worked –  Saul Ortega yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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