Ubuntu – Run Bash Script as Root

bashpasswordrootsudo

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?

Best Answer

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.

Related Question