all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* sudo in emacs
@ 2012-01-06  0:47 Rajanikanth Jammalamadaka
  2012-01-06  6:46 ` Harold Pimentel
  2012-01-10 15:03 ` Chris Poole
  0 siblings, 2 replies; 5+ messages in thread
From: Rajanikanth Jammalamadaka @ 2012-01-06  0:47 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]

Hi

My work environment requires that I sudo to an administrative userid using:

sudo -u userid sudo-sh

I normally run emacs using my login userid which is different from the
administrative userid.

Is there a way I can do this using tramp?

The problem of doing this from shell/eshell is that I am able to login
using the above sudo command but when I open a file using C-x C-f, the
files
are opening with my userid rather than the administrative userid.

Is there a workaround for this?

Thanks,
Raj

[-- Attachment #2: Type: text/html, Size: 740 bytes --]

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

* Re: sudo in emacs
  2012-01-06  0:47 sudo in emacs Rajanikanth Jammalamadaka
@ 2012-01-06  6:46 ` Harold Pimentel
  2012-01-10 15:03 ` Chris Poole
  1 sibling, 0 replies; 5+ messages in thread
From: Harold Pimentel @ 2012-01-06  6:46 UTC (permalink / raw)
  To: Rajanikanth Jammalamadaka; +Cc: help-gnu-emacs

Does this help?

http://emacs-fu.blogspot.com/2011/12/system-administration-with-emacs.html

(also see the link in the text 'editing files owned by root with tramp')

Harold

On Thu, Jan 5, 2012 at 4:47 PM, Rajanikanth Jammalamadaka
<rajanikanth@gmail.com> wrote:
>
> Hi
>
> My work environment requires that I sudo to an administrative userid using:
>
> sudo -u userid sudo-sh
>
> I normally run emacs using my login userid which is different from the administrative userid.
>
> Is there a way I can do this using tramp?
>
> The problem of doing this from shell/eshell is that I am able to login using the above sudo command but when I open a file using C-x C-f, the files
> are opening with my userid rather than the administrative userid.
>
> Is there a workaround for this?
>
> Thanks,
> Raj
>
>



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

* Re: sudo in emacs
  2012-01-06  0:47 sudo in emacs Rajanikanth Jammalamadaka
  2012-01-06  6:46 ` Harold Pimentel
@ 2012-01-10 15:03 ` Chris Poole
  2012-01-10 15:09   ` Tassilo Horn
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Poole @ 2012-01-10 15:03 UTC (permalink / raw)
  To: Rajanikanth Jammalamadaka; +Cc: help-gnu-emacs

On Thu, Jan 5, 2012 at 4:47 PM, Rajanikanth Jammalamadaka
<rajanikanth@gmail.com> wrote:

> Is there a way I can do this using tramp?

On a file by file basis, I use this:

    (defun find-alternative-file-with-sudo ()
      "Open the current buffer with privileges given by `sudo'."
      (interactive)
      (when buffer-file-name
        (find-alternate-file
         (concat "/sudo:root@localhost:"
    	     buffer-file-name))))


Cheers

Chris



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

* Re: sudo in emacs
  2012-01-10 15:03 ` Chris Poole
@ 2012-01-10 15:09   ` Tassilo Horn
  2012-01-10 16:33     ` Richard Riley
  0 siblings, 1 reply; 5+ messages in thread
From: Tassilo Horn @ 2012-01-10 15:09 UTC (permalink / raw)
  To: help-gnu-emacs

Chris Poole <lists@chrispoole.com> writes:

> On Thu, Jan 5, 2012 at 4:47 PM, Rajanikanth Jammalamadaka
> <rajanikanth@gmail.com> wrote:
>
>> Is there a way I can do this using tramp?
>
> On a file by file basis, I use this:
>
>     (defun find-alternative-file-with-sudo ()
>       "Open the current buffer with privileges given by `sudo'."
>       (interactive)
>       (when buffer-file-name
>         (find-alternate-file
>          (concat "/sudo:root@localhost:"
>     	     buffer-file-name))))

First of all as an answer to the OP, you can just do

  C-x C-f /sudo:userid@localhost:/foo/bar/baz.txt RET

Because I'm lazy, I have a similar hack in my .emacs:

--8<---------------cut here---------------start------------->8---
(defun th-find-file-sudo (file)
  "Opens FILE with root privileges."
  (interactive "F")
  (set-buffer (find-file (concat "/sudo::" file))))

(defadvice find-file (around th-find-file activate)
  "Open FILENAME using tramp's sudo method if it's read-only."
  (if (and (not (file-writable-p (ad-get-arg 0)))
	   (not (file-remote-p (ad-get-arg 0)))
	   (y-or-n-p (concat "File "
			     (ad-get-arg 0)
			     " is read-only.  Open it as root? ")))
      (th-find-file-sudo (ad-get-arg 0))
    ad-do-it))
--8<---------------cut here---------------end--------------->8---

So if I try to open a file for which I don't have permissions for, I'm
queried if I want to open it as root using the sudo tramp method.

Bye,
Tassilo




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

* Re: sudo in emacs
  2012-01-10 15:09   ` Tassilo Horn
@ 2012-01-10 16:33     ` Richard Riley
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Riley @ 2012-01-10 16:33 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@member.fsf.org> writes:

> --8<---------------cut here---------------start------------->8---
> (defun th-find-file-sudo (file)
>   "Opens FILE with root privileges."
>   (interactive "F")
>   (set-buffer (find-file (concat "/sudo::" file))))
>
> (defadvice find-file (around th-find-file activate)
>   "Open FILENAME using tramp's sudo method if it's read-only."
>   (if (and (not (file-writable-p (ad-get-arg 0)))
> 	   (not (file-remote-p (ad-get-arg 0)))
> 	   (y-or-n-p (concat "File "
> 			     (ad-get-arg 0)
> 			     " is read-only.  Open it as root? ")))
>       (th-find-file-sudo (ad-get-arg 0))
>     ad-do-it))
> --8<---------------cut here---------------end--------------->8---

Oh, very nice. nicked... ;)




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

end of thread, other threads:[~2012-01-10 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-06  0:47 sudo in emacs Rajanikanth Jammalamadaka
2012-01-06  6:46 ` Harold Pimentel
2012-01-10 15:03 ` Chris Poole
2012-01-10 15:09   ` Tassilo Horn
2012-01-10 16:33     ` Richard Riley

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.