Is there some way I can run a Bash script as root without being prompted for a password every time? I'm attempting to automate the process of starting my LAMPP install, which requires me running a couple of sudo commands to start and stop services. Optimally, I'd like to build this into an executable file, so all I'd have to do is click an icon. ;)

Obviously, I have the password, so that's not an issue. I just want to take my laziness one step farther and not have to enter it every time I start my localhost. After all, that's what programming is all about, right?

  • You can automate starting services such as LAMP on boot up; there should be no need to use a sudo-bash hack. – ish Jun 20 '12 at 5:28
  • I thought about that, but I don't necessarily want my localhost running all the time. Just when I actually need it. – Scotty C. Jun 20 '12 at 5:38

You could add the script to your sudoers configuration file:

sudo visudo

Then find the following:

%sudo ALL=(ALL) ALL

add after:

 your_username ALL=(ALL) NOPASSWD: /path/to/your/script

CTRL+X and confirm.

| improve this answer | |
  • Okay, I did something wrong, but I don't know what it was. It's still prompting for a password on both of the commands. :S The sudoers file edit: scotty ALL=(ALL) NOPASSWD: /opt/lampp/startup.sh The few lines of my executable script: #!/bin/bash sudo /opt/lampp/lampp startapache sudo /opt/lampp/lampp startmysql – Scotty C. Jun 20 '12 at 6:00
  • Obviously the above scripts span multiple lines, but the comments here don't show it. – Scotty C. Jun 20 '12 at 6:05
  • Did you reboot? – jasmines Jun 20 '12 at 6:41
  • @jasmines, I think you should at least give a warning for the process. – Anwar Jun 20 '12 at 7:07
  • @jasmines Hey, sorry it took so long to get back to this. Been up to my ears in work lately. Anyway, yes, I did reboot, and the executable file is still asking for my password. – Scotty C. Jun 22 '12 at 21:19

You can open a terminal, then "sudo gnome-terminal", enter the password and just copy, paste the commands to install LAMPP. Or you can write a script, "run.sh" for example, and run "sudo sh run.sh". Hope that helps.

| improve this answer | |
  • 2
    OP was asking for ways to run WITHOUT entering password. If you include modifying sudoers file to allow running just this script with NOPASSWORD, it can be an answer. In its present form, however, it is invalid. – Mahesh Jun 20 '12 at 7:59

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.