3

Since my Asus VivoBook keyboard shortcut to change de keyboard lightning level is not working, I made a bash script and configured it to be activated when I press a combination of keys. This is my script:

level=$(cat /sys/class/leds/asus\:\:kbd_backlight/brightness)

[[ $level = 3 ]] && echo 0 | sudo tee /sys/class/leds/asus\:\:kbd_backlight/brightness || echo $(($level+1)) | sudo tee /sys/class/leds/asus\:\:kbd_backlight/brightness

The script is working when I run it on terminal, but when I press the keys, it doesn't, I think because of the sudo permission that requires a password. Is there any way I can change the script permissions so that when I run it in the background it doesn't request for the password?

1 Answers1

1

There may be several options to do so, but I am suggesting you three options:

One way is to use sudo -i instead of sudo The command is run with an environment similar to the one a user would receive at log in.

The other way is to use sudo -v instead of sudo which uses cached credentials.

The third option is to configure sudo to never ask you for a password. The visudo command edits the sudoers file, which is used by the sudo command. To change what users and groups are allowed to run sudo, run visudo

sudo visudo

In the bottom of the file, add the following line:

<username> ALL=(ALL) NOPASSWD: ALL

Replace the with your user name. Example, I will add the line

tejas ALL=(ALL) NOPASSWD: ALL 

Once this line is added, you can type sudo in a Terminal window without being prompted for the password.

Note that this solution applies only while to using the sudo command in the terminal.

To restrict the location in which the script can be excuted without password prompt, use the folllowing command:

<username> ALL=NOPASSWD:/bin/bash /path/to/script/*

Strict note: use this solution only for the scripts which you can trust.