LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do I use sudo in a script without asking for password? (https://www.linuxquestions.org/questions/linux-general-1/how-do-i-use-sudo-in-a-script-without-asking-for-password-666116/)

Usalabs 08-28-2008 01:44 PM

How do I use sudo in a script without asking for password?
 
I've written a small script that creates a network bridge for a virtual machine (vbox), but each line requires root access, ie sudo, I've added my user name to the sudoers file using visudo:

user ALL=(ALL) ALL

and I added my user group also:

%group ALL=(ALL) ALL

rebooted, and still, each line in the script shows a permission denied:

Code:

#!/bin/bash

# Check if interface exists, if so delete it

if [ -z "vbox0" ]; then
VBoxDeleteIF vbox0
fi

# Create virtual connection br0

brctl addbr br0

# Clear eth0 setting

ifconfig eth0 0.0.0.0

# Create bridge

brctl addif br0 eth0

# Change etho setting to br0

dhclient br0

# Create virtual vbox host

VBoxAddIF vbox0 <user> br0

I even set the execute bit for the script.

I would like to run the script without asking for a password for the script and for each line.

When I either power down or reboot, the br0 connection is lost and I have to manually remove vbox0 and re-create br0, is there a way to make br0 permanent? or have the system run the above script at start up, I'm using Ubuntu (Hardy).

trickykid 08-28-2008 01:59 PM

It's in the man page but it would look something like this:

Code:

user ALL=(ALL) NOPASSWD: ALL


All times are GMT -5. The time now is 12:07 AM.