[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacs idiom for sudo
Re: emacs idiom for sudo
Tue, 22 May 2007 18:29:47 +1000
Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)
Amy Templeton <address@hidden> writes:
> Tim X <address@hidden> wrote:
>> "Rustom Mody" <address@hidden> 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
>> 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
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.
tcross (at) rapttech dot com dot au
Message not available