Gentoo Archives: gentoo-user

From: Alexander Skwar <listen@×××××××××××××××.name>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] sudo echo
Date: Thu, 23 Mar 2006 22:52:14
Message-Id: 44231822.7010708@mid.email-server.info
In Reply to: Re: [gentoo-user] sudo echo by Holly Bostick
1 Holly Bostick wrote:
2 > JimD schreef:
3 >> I have been using Linux for a number of years and the one "trick" I
4 >> have never read how to do is something like:
5 >>
6 >> sudo echo "app-portage/porthole ~*" >> /etc/portage/package.keywords
7 >
8 > Well this one I do with a set of revised command nicked from the list,
9 > entered into ~/.bashrc, and requiring that
10 >
11 > 1) "su" is one of the commands that you are allowed to execute via sudo
12 >
13 > 2) you are exempted from needing to enter a password for 'sudo su':
14 >
15 > addkey(){
16 > sudo su -c "echo $* >> /etc/portage/package.keywords"
17 > }
18
19 What's the use of su here? I don't understand.
20
21 What's happening is, that a root process executes
22
23 su -c "echo $* >> /etc/portage/package.keywords"
24
25 But why switch user from root to root to execute
26
27 echo $* >> /etc/portage/package.keywords
28
29 I don't understand that. Please explain.
30
31 > The general idea being that a) sudo seems to be a bit weird; even though
32 > it allows you to perform operations as if you are root, it doesn't do so
33 > by pretending that you _are_ root,
34
35 Uh? What are you talking about? The command is run with root
36 rights. If you use "sudo -H", even $HOME is set to ~root.
37
38 > so you still couldn't write to the
39 > /etc/portage/package.* files;
40
41 Yes, you can. The error is, that with
42
43 sudo echo blah >> file
44
45 Here the NORMAL USER does ">> file", *NOT* the root
46 echo process!
47
48 Have a read in your shell manpage.
49
50 > b) su does pretend you are root,
51
52 What do you mean with that?
53
54
55 >> Another one I always wanted to know if it is possible is:
56 >>
57 >> sudo > /var/log/foo.log
58 >
59 > I'm sure it is, with a bit of creativity, though I honestly don't know
60 > what your intention is in any case, since this looks to me like you're
61 > logging the output of the sudo command to foo.log (but since there is no
62 > output really to typing 'sudo', I have no idea what result you might
63 > expect).
64
65 A truncated file is to be expected, as that's what's happening
66 when you do
67
68 > filename
69
70 > Anyway, hope this is to some degree helpful; what you most likely want
71 > to do is read up on bash scripting to understand how to chain the
72 > commands that do what you want to get done with sudo.
73
74 Yep.
75
76 Alexander Skwar
77 --
78 Keep brain from freezing.
79
80 -- Homer Simpson
81 Simpson and Delilah
82 --
83 gentoo-user@g.o mailing list