LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Strange sudo limitation. Why? (https://www.linuxquestions.org/questions/linux-software-2/strange-sudo-limitation-why-4175557658/)

mreff555 10-31-2015 05:22 PM

Strange sudo limitation. Why?
 
Lets say I feel like reducing my screen brightness. However, rather than the laborious task of taking my fingers off the home row and pressing a button, I would rather type a sentence like this.

Code:

sudo echo 8 < /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness
actually, this doesn't work. It should, but I get a permission denied. However

Code:

su
echo 8 < /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness
exit

if I invoke su rather than sudo it works.

typing a complicated sentence isn't a problem but those extra 6 characters and carrige returns are killing me. What gives?? :banghead:

rknichols 10-31-2015 05:31 PM

I think you meant ">" instead of "<" .

For the first case, it's your current, unprivileged shell that is trying to open that path for output. For the second case, "su" starts a privileged shell and it that that shell that is doing the open. If you want to do it in a single line try
Code:

sudo sh -c 'echo 8 > /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness'
Looks to me like a good spot for an alias if you're doing that often.

hortageno 10-31-2015 05:34 PM

Quote:

Originally Posted by mreff555 (Post 5442964)
Lets say I feel like reducing my screen brightness. However, rather than the laborious task of taking my fingers off the home row and pressing a button, I would rather type a sentence like this.

Code:

sudo echo 8 < /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness
actually, this doesn't work. It should, but I get a permission denied. However

Code:

su
echo 8 < /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness
exit

if I invoke su rather than sudo it works.

typing a complicated sentence isn't a problem but those extra 6 characters and carrige returns are killing me. What gives?? :banghead:

To me it's logical. If root allows you to execute certain command(s) with higher privileges it doesn't mean at the same time that you are allowed to write to any of his files.

BTW you got the ">" wrong...

mreff555 10-31-2015 07:05 PM

Quote:

Originally Posted by hortageno (Post 5442971)
To me it's logical. If root allows you to execute certain command(s) with higher privileges it doesn't mean at the same time that you are allowed to write to any of his files.

BTW you got the ">" wrong...

whoops

nelz 11-04-2015 10:50 AM

As others have said, you are running the echo as root but the redirection as the user. No one has said how to do it the other way round, which is to use tee.

echo 8 | sudo tee sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness

This has the added benefit of avoiding the embarrassment of getting your redirection symbols the wrong way round ;-)

rtmistler 11-04-2015 12:04 PM

Quote:

Originally Posted by nelz (Post 5444572)
As others have said, you are running the echo as root but the redirection as the user. No one has said how to do it the other way round, which is to use tee.

echo 8 | sudo tee sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness

This has the added benefit of avoiding the embarrassment of getting your redirection symbols the wrong way round ;-)

Maybe but I never seemed to misunderstand where an arrow is pointing. A good rule of thumb is to teach ones self that the direction of those input/output redirectors is from the larger side to the point. I'm not sure one benefits by avoiding use of > and <

TobiSGD 11-04-2015 01:18 PM

Quote:

Originally Posted by mreff555 (Post 5442964)
Lets say I feel like reducing my screen brightness. However, rather than the laborious task of taking my fingers off the home row and pressing a button, I would rather type a sentence like this.

Code:

sudo echo 8 < /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness
actually, this doesn't work. It should, but I get a permission denied. However

Code:

su
echo 8 < /sys/class/i2c-adaptor/i2c-7/device/backlight/acpi_video0/brightness
exit

if I invoke su rather than sudo it works.

typing a complicated sentence isn't a problem but those extra 6 characters and carrige returns are killing me. What gives?? :banghead:

Now that your sudo problem is explained, if the number of keystrokes is an issue, why not just use tools that make it even easier, like xbacklight or light? Even less keystrokes and no problems with sudo/su.


All times are GMT -5. The time now is 09:43 AM.