Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need execute script that have commands which should be run in root mode. If I put sudo before command then when I run script I see permission denied ( I don't have a chance to write password). If I run script with sudo then it writes - command not found. If I put sudo su in the beginning of the script then after I inter password nothing happens. Script executes only when exit root mode. How can make such script? Thank you.

share|improve this question
up vote 3 down vote accepted

You can set a script to not require a password via sudo with e.g. the following in /etc/sudoers:

user   ALL=(ALL:ALL) NOPASSWD: /path/to/your/script
share|improve this answer
@:jmtd I did not but it on sudo myscript it still ask password – ashim Mar 14 '12 at 20:44
@user16610 See How to run a specific program as root without a password prompt? : the more specific rule needs to come after the more general rule. – Gilles Mar 14 '12 at 23:20

(Posted as a new answer since I can't comment & the edit is too small)

You can end the command with "" to prevent the user from running the command with arbitrary arguments.

user ALL=(ALL:ALL) NOPASSWD: /path/to/your/script ""

Now sudo /path/to/your/script works but sudo /path/to/your/script foo bar fails.

share|improve this answer

Your Answer


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.