0
votes

I'm trying to run a script without ask for root password. So i have a script.sh with several sudo commands inside and I've modified the file sudoers with "sudo visudo" to be able to run the script without ask for root password :

%sudo ALL=(ALL:ALL) ALL root ALL=(ALL) NOPASSWD: /home/user/script.sh

as well I've change the user and group of my script (sudo chown root.root script.sh) and change the as well (sudo chmod 777 script.sh) , but always that I try to run my script it ask for root password, and I don't idea what can it be

Note: I tried as well change this > user ALL=(ALL) NOPASSWD: /home/user/script.sh , and the user,group to (user) and I still have the same issue.

1
Hope this helps; be sure to follow it to the letter - askubuntu.com/questions/155791/…Ruud Helderman

1 Answers

1
votes

remove all sudo commands in your script. Just put the below lines at the beginning of your script

#!/bin/bash
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
    echo "Aborting: run as root user!"
    exit 1
fi

#... your program

This makes the whole script to be run with super user. and none of the commands in your script needs sudo prefix.