I want to make a script that changes screen brightness and, among others, need this command:
echo "$number" | sudo tee /sys/class/backlight/intel_backlight/brightness
[sudo] password for user:
You might configure your system so that
sudo does not ask for any password. I don't recommend doing this (put
ALL=NOPASSWD: in your
/etc/sudoers file at appropriate place), since it is a security hole.
But what you really want would be to make a setuid executable (BTW
/usr/bin/sudo is itself a setuid executable). It is tricky to understand, and you can make huge mistakes (opening large security holes). Read also carefully execve(2) & Advanced Linux Programming. Spend several hours to understand the setuid thing (if you misunderstand it, you'll have security issues). See also credentials(7) & capabilities(7).
For security reasons, shell scripts cannot be made setuid. So you can code a tiny wrapper in C which would run the script thru
execve after appropriate calls (e.g. to setresuid(2) and friends), compile that C program as a setuid executable (so
chown root and
chmod u+s your executable). In your particular case you don't even need to code a C program starting a shell command (you just should
/sys/class/backlight/intel_backlight/brightness pseudo-file then
fprintf into it, and
Actually, I don't believe that doing all that is necessary, because you should be able to configure your system to let your screen brightness be set by non root. I have no idea how to do that precisely (but that is a different question).