unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* emacs idiom for sudo
@ 2007-05-20  4:01 Rustom Mody
  2007-05-20  5:19 ` Eric Hanchrow
  2007-05-22  4:38 ` Xavier Maillard
  0 siblings, 2 replies; 17+ messages in thread
From: Rustom Mody @ 2007-05-20  4:01 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 174 bytes --]

Is there a more convenient way for doing 'root-things' than
-- get out of emacs (maybe suspend)
-- start a shell
-- sudo editor (usually vi) OR su ... password... editor

??

[-- Attachment #1.2: Type: text/html, Size: 201 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-20  4:01 emacs idiom for sudo Rustom Mody
@ 2007-05-20  5:19 ` Eric Hanchrow
  2007-05-21 12:07   ` Rustom Mody
  2007-05-22  2:38   ` Matthew Flaschen
  2007-05-22  4:38 ` Xavier Maillard
  1 sibling, 2 replies; 17+ messages in thread
From: Eric Hanchrow @ 2007-05-20  5:19 UTC (permalink / raw)
  To: help-gnu-emacs


    Is there a more convenient way for doing 'root-things' than
    -- get out of emacs (maybe suspend)
    -- start a shell
    -- sudo editor (usually vi) OR su ... password... editor

Indeed there is -- use "tramp", by doing, e.g.,

        C-x C-f /sudo::/etc/passwd RET

Read (info "(emacs)Remote Files")
-- 
When a cryptographer and a symbologist get together, it
usually ends in tears.
        A. O. Scott, reviewing 'The Da Vinci Code' in the New York Times

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
       [not found] <mailman.880.1179633671.32220.help-gnu-emacs@gnu.org>
@ 2007-05-20  5:58 ` Tim X
  2007-05-22  4:18   ` Amy Templeton
       [not found]   ` <mailman.947.1179807172.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Tim X @ 2007-05-20  5:58 UTC (permalink / raw)
  To: help-gnu-emacs

"Rustom Mody" <rustompmody@gmail.com> writes:

> Is there a more convenient way for doing 'root-things' than
> -- get out of emacs (maybe suspend)
> -- start a shell
> -- sudo editor (usually vi) OR su ... password... editor
>

I use tramp to do this. Essentially, using either a 'su' or 'sudo' tramp method
to edit a local file. This is described in the tramp manual. 

tim

-- 
tcross (at) rapttech dot com dot au

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-20  5:19 ` Eric Hanchrow
@ 2007-05-21 12:07   ` Rustom Mody
  2007-05-22  2:38   ` Matthew Flaschen
  1 sibling, 0 replies; 17+ messages in thread
From: Rustom Mody @ 2007-05-21 12:07 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 384 bytes --]

Thanks Eric (and others)

The only thing that increases after > 12 years of emacs is the amount I know
I dont know.

Rustom

On 5/20/07, Eric Hanchrow <offby1@blarg.net> wrote:
>
>
>     Is there a more convenient way for doing 'root-things' than
>
>
> Indeed there is -- use "tramp", by doing, e.g.,
>
>         C-x C-f /sudo::/etc/passwd RET
>
> Read (info "(emacs)Remote Files")
>

[-- Attachment #1.2: Type: text/html, Size: 784 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-20  5:19 ` Eric Hanchrow
  2007-05-21 12:07   ` Rustom Mody
@ 2007-05-22  2:38   ` Matthew Flaschen
  1 sibling, 0 replies; 17+ messages in thread
From: Matthew Flaschen @ 2007-05-22  2:38 UTC (permalink / raw)
  To: emacs

Eric Hanchrow wrote:
>     Is there a more convenient way for doing 'root-things' than
>     -- get out of emacs (maybe suspend)
>     -- start a shell
>     -- sudo editor (usually vi) OR su ... password... editor
> 
> Indeed there is -- use "tramp", by doing, e.g.,
> 
>         C-x C-f /sudo::/etc/passwd RET

Thanks!  A little hackish, but it works.

Matt Flaschen

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-20  5:58 ` Tim X
@ 2007-05-22  4:18   ` Amy Templeton
       [not found]   ` <mailman.947.1179807172.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 17+ messages in thread
From: Amy Templeton @ 2007-05-22  4:18 UTC (permalink / raw)
  To: help-gnu-emacs

Tim X <timx@nospam.dev.null> wrote:
> "Rustom Mody" <rustompmody@gmail.com> writes:
> > Is there a more convenient way for doing 'root-things' than
> > -- get out of emacs (maybe suspend)
> > -- start a shell
> > -- sudo editor (usually vi) OR su ... password... editor

> I use tramp to do this. Essentially, using either a 'su' or 'sudo' tramp method
> to edit a local file. This is described in the tramp manual.

What about executing some elisp code as root (obviously including a
password prompt, not just executing it without any question)? Or is
it necessary to just start a whole new Emacs? I didn't see anything
about this in the tramp manual, but I might not be looking hard
enough.

Amy

-- 
Clovis' Consideration of an Atmospheric Anomaly:
        The perversity of nature is nowhere better demonstrated
        than by the fact that, when exposed to the same atmosphere,
        bread becomes hard while crackers become soft.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-20  4:01 emacs idiom for sudo Rustom Mody
  2007-05-20  5:19 ` Eric Hanchrow
@ 2007-05-22  4:38 ` Xavier Maillard
  1 sibling, 0 replies; 17+ messages in thread
From: Xavier Maillard @ 2007-05-22  4:38 UTC (permalink / raw)
  To: Rustom Mody; +Cc: help-gnu-emacs

Hi,

   Is there a more convenient way for doing 'root-things' than
   -- get out of emacs (maybe suspend)
   -- start a shell
   -- sudo editor (usually vi) OR su ... password... editor

   ??

Yes, there is one: Tramp[1]

	Xavier

[1] http://www.emacswiki.org/cgi-bin/wiki/TrampMode
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
       [not found]   ` <mailman.947.1179807172.32220.help-gnu-emacs@gnu.org>
@ 2007-05-22  8:29     ` Tim X
  2007-05-22 14:25       ` foo@bar.baz
                         ` (2 more replies)
  2007-05-22 22:53     ` David Kastrup
  1 sibling, 3 replies; 17+ messages in thread
From: Tim X @ 2007-05-22  8:29 UTC (permalink / raw)
  To: help-gnu-emacs

Amy Templeton <amy.g.templeton@gmail.com> writes:

> Tim X <timx@nospam.dev.null> wrote:
>> "Rustom Mody" <rustompmody@gmail.com> writes:
>> > Is there a more convenient way for doing 'root-things' than
>> > -- get out of emacs (maybe suspend)
>> > -- start a shell
>> > -- sudo editor (usually vi) OR su ... password... editor
>
>> I use tramp to do this. Essentially, using either a 'su' or 'sudo' tramp method
>> to edit a local file. This is described in the tramp manual.
>
> What about executing some elisp code as root (obviously including a
> password prompt, not just executing it without any question)? Or is
> it necessary to just start a whole new Emacs? I didn't see anything
> about this in the tramp manual, but I might not be looking hard
> enough.
>

Thats going to be considerably harder to do. The tramp method for editing files
works well because all your really doing is wrapping  find-file and save-file
inside scp/ssh and hiding all the gory/boring details under elisp. However,
executing a command as another user from within emacs is a bit more difficult,
depending on the command you want to run. 

If the command is just a basic non-interactive or has trivial shell type
interaction, then its doable. But if it has more complex IO requirements, its
going to require a little more thought. 

I often execute a program as root by opening a term buffer and doing a su/sudo.
In the past, I've written a bit of elisp to automate such processes (using ssh
and an ssh--agent keys to make issues of password prompts go away etc)..
However, if the program I want to run requires extensive access to lower level
screen IO functions, things can become a bit 'hairy'. 

If you want to execute elisp as another user, well, thats going to be a fair
bit more complicated - I'm not sure how you would approach that sort of
problem. You can't use your existing emacs as the interpreter as it is running
in the wrong environment -= you would need to spawn of some sort of sub-shell
and then somehow get an elisp interpreter (write one in another lisp perhaps?).
You may be able to do something with emacsclient, but you woul dstill need an
emacs running somewhere as the user you want th e code to run as. 

Probably more of a hassle than its worth - but that depends on your
environment/needs I guess.

Tim


-- 
tcross (at) rapttech dot com dot au

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-22  8:29     ` Tim X
@ 2007-05-22 14:25       ` foo@bar.baz
  2007-05-22 17:11         ` Peter Dyballa
                           ` (2 more replies)
  2007-05-22 20:45       ` Michael Albinus
       [not found]       ` <mailman.1025.1179866756.32220.help-gnu-emacs@gnu.org>
  2 siblings, 3 replies; 17+ messages in thread
From: foo@bar.baz @ 2007-05-22 14:25 UTC (permalink / raw)
  To: help-gnu-emacs

On May 22, 10:29 am, Tim X <t...@nospam.dev.null> wrote:
> You may be able to do something with emacsclient, but you woul dstill need an
> emacs running somewhere as the user you want th e code to run as.
>
> Probably more of a hassle than its worth - but that depends on your
> environment/needs I guess.

I often use emacsclient to edit files from the terminal. With files
that I have to edit as root I have to switch to emacs, start tramp,
find the file...
Is it possible to use emacsclient with sudo?

I tried 'sudo emacsclient file', but this didn't work.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-22 14:25       ` foo@bar.baz
@ 2007-05-22 17:11         ` Peter Dyballa
  2007-05-22 21:45         ` Xavier Maillard
  2007-05-23  4:13         ` Tim X
  2 siblings, 0 replies; 17+ messages in thread
From: Peter Dyballa @ 2007-05-22 17:11 UTC (permalink / raw)
  To: foo@bar.baz; +Cc: Emacs Help [help-gnu-emacs]


Am 22.05.2007 um 16:25 schrieb foo@bar.baz:

> Is it possible to use emacsclient with sudo?

No. Emacs is doing things, its client is some go-between.

--
Greetings

   Pete

   It's not the valleys in life I dread so much as the dips.
                     -- Garfield

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-22  8:29     ` Tim X
  2007-05-22 14:25       ` foo@bar.baz
@ 2007-05-22 20:45       ` Michael Albinus
       [not found]       ` <mailman.1025.1179866756.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 17+ messages in thread
From: Michael Albinus @ 2007-05-22 20:45 UTC (permalink / raw)
  To: help-gnu-emacs

Tim X <timx@nospam.dev.null> writes:

> Amy Templeton <amy.g.templeton@gmail.com> writes:
>
>> Tim X <timx@nospam.dev.null> wrote:
>>> "Rustom Mody" <rustompmody@gmail.com> writes:
>>> > Is there a more convenient way for doing 'root-things' than
>>> > -- get out of emacs (maybe suspend)
>>> > -- start a shell
>>> > -- sudo editor (usually vi) OR su ... password... editor
>>
>>> I use tramp to do this. Essentially, using either a 'su' or 'sudo' tramp method
>>> to edit a local file. This is described in the tramp manual.
>>
>> What about executing some elisp code as root (obviously including a
>> password prompt, not just executing it without any question)? Or is
>> it necessary to just start a whole new Emacs? I didn't see anything
>> about this in the tramp manual, but I might not be looking hard
>> enough.
>>
>
> Thats going to be considerably harder to do. The tramp method for editing files
> works well because all your really doing is wrapping  find-file and save-file
> inside scp/ssh and hiding all the gory/boring details under elisp. However,
> executing a command as another user from within emacs is a bit more difficult,
> depending on the command you want to run. 

<advertising>
Tramp 2.1 (NOT part of Emacs 22.1) provides an implementation for
call-process and start-process, which let's the corresponding processes
run on the remote host when default-directory points to such. It is
experimental code, but it does a good job for me also in the sudo case
(no wonder, I did implement it :-)

It also cooperates with compile.el, grep.el, gdb.el, eshell.el - just to
mention the major packages I apply myself.
</advertising>

> Tim

Best regards, Michael.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-22 14:25       ` foo@bar.baz
  2007-05-22 17:11         ` Peter Dyballa
@ 2007-05-22 21:45         ` Xavier Maillard
  2007-05-23  4:13         ` Tim X
  2 siblings, 0 replies; 17+ messages in thread
From: Xavier Maillard @ 2007-05-22 21:45 UTC (permalink / raw)
  To: foo@bar.baz; +Cc: help-gnu-emacs

Hi,

   Is it possible to use emacsclient with sudo?

AFAIK, it can not.

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
       [not found]   ` <mailman.947.1179807172.32220.help-gnu-emacs@gnu.org>
  2007-05-22  8:29     ` Tim X
@ 2007-05-22 22:53     ` David Kastrup
  2007-05-23 10:33       ` reader
  1 sibling, 1 reply; 17+ messages in thread
From: David Kastrup @ 2007-05-22 22:53 UTC (permalink / raw)
  To: help-gnu-emacs

Amy Templeton <amy.g.templeton@gmail.com> writes:

> Tim X <timx@nospam.dev.null> wrote:
>> "Rustom Mody" <rustompmody@gmail.com> writes:
>> > Is there a more convenient way for doing 'root-things' than
>> > -- get out of emacs (maybe suspend)
>> > -- start a shell
>> > -- sudo editor (usually vi) OR su ... password... editor
>
>> I use tramp to do this. Essentially, using either a 'su' or 'sudo' tramp method
>> to edit a local file. This is described in the tramp manual.
>
> What about executing some elisp code as root (obviously including a
> password prompt, not just executing it without any question)? Or is
> it necessary to just start a whole new Emacs? I didn't see anything
> about this in the tramp manual, but I might not be looking hard
> enough.

M-x eshell RET
cd /sudo::/etc RET

and then working on will do quite a number of things at priviledged
level.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-22 14:25       ` foo@bar.baz
  2007-05-22 17:11         ` Peter Dyballa
  2007-05-22 21:45         ` Xavier Maillard
@ 2007-05-23  4:13         ` Tim X
  2 siblings, 0 replies; 17+ messages in thread
From: Tim X @ 2007-05-23  4:13 UTC (permalink / raw)
  To: help-gnu-emacs

"foo@bar.baz" <Simon.Me@gmail.com> writes:

> On May 22, 10:29 am, Tim X <t...@nospam.dev.null> wrote:
>> You may be able to do something with emacsclient, but you woul dstill need an
>> emacs running somewhere as the user you want th e code to run as.
>>
>> Probably more of a hassle than its worth - but that depends on your
>> environment/needs I guess.
>
> I often use emacsclient to edit files from the terminal. With files
> that I have to edit as root I have to switch to emacs, start tramp,
> find the file...
> Is it possible to use emacsclient with sudo?
>

No, from your description its not going to work. If you think about processes,
shells and permissions, the problems are fairly clear. When you run sudo, you
start a new shell process running as the user you have sudo'd to. If you wanted
to use emacsclient to edit the file, emacsclient would need an emacs running as
that user that it can pass to, but if you have emacs running as that user, why
would you bother sudoing to that user to edit the file - you would just edit it
within the emacs running as that user. 

For editing files as another user (such as root), the easiest solution is just
to use tramp. Executing a program as another user from within emacs can be done
via an emacs term, in which you run sudo. running some elisp as another user is
much more difficult because of the seperation of privileges that is the
foundation of the security model under *nix systems.

Tim

-- 
tcross (at) rapttech dot com dot au

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
       [not found]       ` <mailman.1025.1179866756.32220.help-gnu-emacs@gnu.org>
@ 2007-05-23  4:18         ` Tim X
  0 siblings, 0 replies; 17+ messages in thread
From: Tim X @ 2007-05-23  4:18 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Albinus <michael.albinus@gmx.de> writes:

> Tim X <timx@nospam.dev.null> writes:
>
>> Amy Templeton <amy.g.templeton@gmail.com> writes:
>>
>>> Tim X <timx@nospam.dev.null> wrote:
>>>> "Rustom Mody" <rustompmody@gmail.com> writes:
>>>> > Is there a more convenient way for doing 'root-things' than
>>>> > -- get out of emacs (maybe suspend)
>>>> > -- start a shell
>>>> > -- sudo editor (usually vi) OR su ... password... editor
>>>
>>>> I use tramp to do this. Essentially, using either a 'su' or 'sudo' tramp method
>>>> to edit a local file. This is described in the tramp manual.
>>>
>>> What about executing some elisp code as root (obviously including a
>>> password prompt, not just executing it without any question)? Or is
>>> it necessary to just start a whole new Emacs? I didn't see anything
>>> about this in the tramp manual, but I might not be looking hard
>>> enough.
>>>
>>
>> Thats going to be considerably harder to do. The tramp method for editing files
>> works well because all your really doing is wrapping  find-file and save-file
>> inside scp/ssh and hiding all the gory/boring details under elisp. However,
>> executing a command as another user from within emacs is a bit more difficult,
>> depending on the command you want to run. 
>
> <advertising>
> Tramp 2.1 (NOT part of Emacs 22.1) provides an implementation for
> call-process and start-process, which let's the corresponding processes
> run on the remote host when default-directory points to such. It is
> experimental code, but it does a good job for me also in the sudo case
> (no wonder, I did implement it :-)
>
> It also cooperates with compile.el, grep.el, gdb.el, eshell.el - just to
> mention the major packages I apply myself.
> </advertising>
>

Thats very interesting - I'll look forward to it reaching stable status. I
suspect this will be a very handy feature when building code on a remote system
- allowing you to use tramp rather than having to run a remote emacs to get the
additional integration from modes that support compilation etc. In fact, I wish
I had it today (working from home and missing my normally well integrated
environment). I know that some modes support remote compilation, but I've never
managed to get them to work in a reliable way or without sacrificing some of
the integration of my emacs environment.

Tim


-- 
tcross (at) rapttech dot com dot au

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-22 22:53     ` David Kastrup
@ 2007-05-23 10:33       ` reader
  2007-05-23 12:02         ` Peter Dyballa
  0 siblings, 1 reply; 17+ messages in thread
From: reader @ 2007-05-23 10:33 UTC (permalink / raw)
  To: help-gnu-emacs

David Kastrup <dak@gnu.org> writes:

> M-x eshell RET
> cd /sudo::/etc RET
>
> and then working on will do quite a number of things at priviledged
> level.

I get:

  Welcome to the Emacs shell

  ~ $ cd /sudo::/etc RET
  Path substring '/sudo::/etc' not found

Are there special packages that need to be loaded first?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: emacs idiom for sudo
  2007-05-23 10:33       ` reader
@ 2007-05-23 12:02         ` Peter Dyballa
  0 siblings, 0 replies; 17+ messages in thread
From: Peter Dyballa @ 2007-05-23 12:02 UTC (permalink / raw)
  To: reader; +Cc: help-gnu-emacs


Am 23.05.2007 um 12:33 schrieb reader@newsguy.com:

> I get:
>
>   Welcome to the Emacs shell
>
>   ~ $ cd /sudo::/etc RET
>   Path substring '/sudo::/etc' not found

Could you try it again with replacing the ``RET´´ string in *eshell*  
with a hit on the return button of your keyboard?

--
Greetings

   Pete

If you're not confused, you're not paying attention.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2007-05-23 12:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-20  4:01 emacs idiom for sudo Rustom Mody
2007-05-20  5:19 ` Eric Hanchrow
2007-05-21 12:07   ` Rustom Mody
2007-05-22  2:38   ` Matthew Flaschen
2007-05-22  4:38 ` Xavier Maillard
     [not found] <mailman.880.1179633671.32220.help-gnu-emacs@gnu.org>
2007-05-20  5:58 ` Tim X
2007-05-22  4:18   ` Amy Templeton
     [not found]   ` <mailman.947.1179807172.32220.help-gnu-emacs@gnu.org>
2007-05-22  8:29     ` Tim X
2007-05-22 14:25       ` foo@bar.baz
2007-05-22 17:11         ` Peter Dyballa
2007-05-22 21:45         ` Xavier Maillard
2007-05-23  4:13         ` Tim X
2007-05-22 20:45       ` Michael Albinus
     [not found]       ` <mailman.1025.1179866756.32220.help-gnu-emacs@gnu.org>
2007-05-23  4:18         ` Tim X
2007-05-22 22:53     ` David Kastrup
2007-05-23 10:33       ` reader
2007-05-23 12:02         ` Peter Dyballa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).