From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: emacs idiom for sudo Date: Tue, 22 May 2007 18:29:47 +1000 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <87abvxdzwk.fsf@lion.rapttech.com.au> References: <87k5v4doio.fsf@lion.rapttech.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1179823248 21059 80.91.229.12 (22 May 2007 08:40:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 22 May 2007 08:40:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 22 10:40:47 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HqPv9-0002Ik-1C for geh-help-gnu-emacs@m.gmane.org; Tue, 22 May 2007 10:40:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HqPv8-0007kw-MY for geh-help-gnu-emacs@m.gmane.org; Tue, 22 May 2007 04:40:42 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!sn-xt-sjc-03!sn-xt-sjc-09!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:AGqF2MInxO2q2WZIZ6QUua/HNDY= Original-X-Complaints-To: abuse@supernews.com Original-Lines: 51 Original-Xref: shelby.stanford.edu gnu.emacs.help:148656 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:44246 Archived-At: Amy Templeton writes: > Tim X wrote: >> "Rustom Mody" 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