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. Commented Sep 14, 2015 at 19:07

1 Answer 1


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
    Commented Sep 14, 2015 at 22:15
  • 2
    Did you sudo the script? Or just type the scripts name? Commented Sep 14, 2015 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
    Commented Sep 19, 2022 at 22:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .