0

I had a script (named script) in bash, and I wanted to allow an user (named "userScript") to run it as root without giving any password.

So, I edited the file /etc/sudoers and added 2 lines at the end :

Cmnd_Alias SCRIPT=/home/userScript/Desktop/script

userScript ALL:NOPASSWD: SCRIPT

(The script in the desktop is a symbolic link to prevent any modification)

It worked perfectly well. After some days, my script was too big, so I rewrote it in python, with multiples files, classes...

So, I changed nothing except the symbolic link's target, but now when I try to run the script, the terminal ask for a password, and give me an error (sorry if it's not exactly the good message, my Ubuntu isn't in English)

Sorry, user userScript isn't allowed to execute "/usr/bin/python script" as root on name_of_my_computer

I run the script like this as user "userScript" :

sudo python script
  • 2
    Why aren't you doing sudo /home/script/Desktop/script.sh? – muru Nov 4 '16 at 15:26
  • Ho, I never try to run a python's script by this way ! I suppose it's possible due to the first line #!/usr/bin/python. I can't try it now, I'll come back after trying the solution later. Thanks ! – julien2313 Nov 4 '16 at 17:34
2

Your problem here is that the command you try to run with sudo is python; the script is first argument to python. Instead , your script should has executable permissions, and you're supposed to run it as sudo script_name.

Second, when you do python script_name , it won't necessarily look for your script, wherever it's stored. You either would have to give full path, or again, have the script itself live in one of directories listed in PATH variable.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.