1

I am trying to execute a bash script as root from a normal user. The story behind is that I need the www-data user to be able to kill a specific process. To avoid having apache being able to go mayhem on processes I've created the following bash script

#!/bin/bash

PID=$(pgrep mono)
kill -9 $PID

To be able to perform this, I have done an apt-get install sudo and then with visudo added the following line to the bottom of the file

myuser ALL= NOPASSWD: /path/to/script/foo.sh

But when I sign into myuser and try to run /path/to/script/foo.sh I receive the following error -bash: /path/to/script/foo.sh: Permission denied

The current permission of the file are as follows

-rwxr-xr-x 1 root root   48 Nov  7 12:11 foo.sh

Thank you!

2 Answers 2

-1

To use sudo, you need to prefix your command with "sudo". ie:

$ sudo /path/to/script/foo.sh
-1

Login with root and do the following:

cd /path/to/script

chmod u+x foo.sh

./foo.sh

Test to see if the program runs. Now switch to myuser,

su myuser

and try to run the program again:

/path/to/script/foo.sh

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.