How to give sudo access to a bash script?

ronnie picture ronnie · Jul 13, 2012 · Viewed 20.4k times · Source

I have a bash script(chbr.sh) to change my display brightness from terminal as my brightness keys doesn't work.

`sudo setpci -s 00:02.0 F4.B=30`

Now, every time I run that script it asks for password which I don't like. So, I googled a little and found out that one can edit /etc/sudoers file to disable the password feature.

So, I edited my sudoers file with the below content

ronnie ALL = (ALL) NOPASSWD: /home/ronnie/chbr.sh

Now when I run my script as ./chbr.sh it again asks for my password. So, is this not the right way to give sudo access to a bash script or what am I doing wrong here.

ronnie@ronnie:~$ ls -l chbr.sh
~rwxrwxr-x 1 ronnie ronnie 46 Jul 13 15:59 /home/ronnie/chbr.sh

Answer

Igor Chubin picture Igor Chubin · Jul 13, 2012

You make all correct, but execute the script with te full path:

$ sudo /home/ronnie/chbr.sh