tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reopening ssh file with sudo


From: Joseph Garvin
Subject: Re: Reopening ssh file with sudo
Date: Sun, 10 Sep 2023 09:17:32 -0500

Yeah, I haven't tried automating tramp much before so I'm not super familiar with what best practice is here. I'm on 29.1.

On Sun, Sep 10, 2023, 9:13 AM Michael Albinus <michael.albinus@gmx.de> wrote:
Joseph Garvin <k04jg02@gmail.com> writes:

Hi Joseph,

> I originally posted this on the emacs stack exchange
> (https://emacs.stackexchange.com/questions/78768/reopen-with-sudo-command-that-works-through-tramp)
> but they suggested I try here.
>
> I have tried to define this command:
>
> ```
> (defun etc-reopen-with-sudo ()
>   (interactive)
>   (let* ((vec (tramp-dissect-file-name (buffer-file-name
> (current-buffer))))
>        (method (tramp-file-name-method vec))
>        (user (tramp-file-name-user vec))
>        (host (tramp-file-name-host vec))
>        (localname (tramp-file-name-localname vec)))
>     (message "localname=%s" localname)
>     (find-alternate-file
>      (if (tramp-tramp-file-p (buffer-file-name (current-buffer)))
>          (concat (format "/%s:%s@%s|sudo::%s" method user host
> localname))
>        (concat "/sudo:root@localhost:" buffer-file-name)))))
> ```
>
> It worked once... and now ever since mysteriously hangs whenever I try
> to use it to open a file with sudo on a remote host with ssh. The idea
> for what file string to use for this comes from
> https://stackoverflow.com/questions/2177687/open-file-via-ssh-and-sudo-with-emacs
> which suggests `/ssh:you@remotehost|sudo:remotehost:/path/to/file`
> should work. I'm able to visit files on the host just fine without
> sudo. Any ideas what I'm doing wrong here?

Well, your function has some flaws. For example, it doesn't handle the
case there's no user in the buffer-file-name, like in
"/ssh:remotehost:/path/to/file". Furthermore, you use the "sudo::"
construct in the second hop, which works reliably since Tramp 2.4 (Emacs
27.1) only. Which versions do you use?

Best regards, Michael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]