LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-31-2015, 05:22 PM   #1
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Rep: Reputation: Disabled
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??
 
Old 10-31-2015, 05:31 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,716

Rep: Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191
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.
 
Old 10-31-2015, 05:34 PM   #3
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 239

Rep: Reputation: 67
Quote:
Originally Posted by mreff555 View Post
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??
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...
 
Old 10-31-2015, 07:05 PM   #4
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hortageno View Post
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
 
Old 11-04-2015, 10:50 AM   #5
nelz
Member
 
Registered: Aug 2004
Posts: 34

Rep: Reputation: 6
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 ;-)
 
1 members found this post helpful.
Old 11-04-2015, 12:04 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Quote:
Originally Posted by nelz View Post
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 <
 
Old 11-04-2015, 01:18 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885
Quote:
Originally Posted by mreff555 View Post
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??
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange PAM/sudo problem (SLES9) chort SUSE / openSUSE 4 02-01-2023 07:20 PM
Question about the sudo command, specifically how to have sudo act as if user is root slacker_ Linux - Newbie 17 09-22-2013 03:48 PM
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
strange sudo problem project722 Linux - Software 1 09-18-2009 09:34 AM
Sudo apt-get update is acting strange Ineedwords1121 Linux - Newbie 1 08-02-2009 12:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration