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?

VaTo
  • 3,101
  • 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

1 Answers1

7

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

ortega ALL=(ALL) NOPASSWD: /path-to-your-script
Noam M
  • 451
Marco
  • 893
  • 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
  • What does ortega mean? I read elsewhere that it has to be my username but using ortega worked which is not my username. All that is required is that it be some non special character there on Linux Mint. – Deoxal Sep 19 '22 at 22:30