[ale] Redirection using sudo...?

Michael Still stillwaxin at gmail.com
Tue Jun 13 13:23:05 EDT 2006


On 6/13/06, Michael B. Trausch <fd0man at gmail.com> wrote:
> Okay, so I know that the shell itself implements redirection.  This is not a
> problem for me, as I use various forms of redirection and piping and such
> all the time.  However, I have wondered if there is a way to change how
> that works.
>
> Sometimes, I want to change something in /proc or /sys.  Doing something
> like:
>
>  $ sudo echo "newvalue" > /sys/something
>
> Will never work, because it says "permission denied" because the redirection
> is done as my local user (in this case, fd0man).
>
> There are other solutions -- write a shell script that does it and execute
> the entire thing under sudo, or do "sudo su" and then perform the task
> using that.  Or, even, write a shell script that takes two arguments, the
> thing to echo, and the (presumably file) to echo it to.  However, I was
> wondering if there was some sort of shell construct that can be used on the
> command line to be something like:
>
>  $ sudo { do something in a subshell as the sudo (root) user; }
>
> I tried simply using a block and that doesn't work, either.  Interesting.
>
> Does anybody know if there is such a thing that can be done such that
> redirection takes the elevated permissions by default, instead of
> redirection as the user running sudo (without creating scripts or using
> su)?
>
>         Thanks!
>         Mike
>

This is a feature that was presumably left out on purpose.  If you
don't trust your users with the root password (or sudo bash or
something like that) then don't let them overwrite arbitrary files.
Suppose they did something like sudo echo
"pwned::0:0:root:/root:/bin/bash" >> /etc/passwd.

-- 
[stillwaxin at gmail.com ~]$ cat .signature
cat: .signature: No such file or directory
[stillwaxin at gmail.com ~]$



More information about the Ale mailing list