如何使用 Emacs trapmp ssh 到远程主机并以另一个用户的身份临时编辑文件?

发布于 2024-12-10 16:14:50 字数 289 浏览 0 评论 0原文

/multi 曾经为我工作,现在它消失了,我很沮丧。

我想做的是,在我的梦想世界中:

/myuser@remotehost:sudo:anotheruser:/some/path/to/file

...并进行 ido 模式工作。

这里的关键是“myuser”、“remotehost”和“anotheruser”都是非常临时的,我使用大量的远程主机,通常使用不同的用户并对各种不同的用户进行 sudo。

我需要添加什么以及如何在不一遍又一遍地重新加载 emacs 的情况下测试它?

/multi used to work for me, now it's gone and I'm frustrated.

What I want to do is, in my dream world:

/myuser@remotehost:sudo:anotheruser:/some/path/to/file

...and have ido-mode work.

The key thing here is that 'myuser', 'remotehost' and 'anotheruser' are all very ad-hoc, I use a huge array of remote hosts, often with different users and sudo-ing to a wide range of different users.

What do I need to add and how can I test it without reloading emacs over and over?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁〃客ぐ 2024-12-17 16:14:50

此提交,TRAMP 再次支持临时多跳。

粗略地说,你可以这样使用它:

/ssh:transituser@remotehost|sudo:user@remotehost:/some/file

我还没有让它在 ido-mode 下可靠地工作,这很遗憾,但总比没有好得多! :-)

As of this commit, TRAMP supports ad-hoc multiple hops again.

Roughly speaking, you use it like this:

/ssh:transituser@remotehost|sudo:user@remotehost:/some/file

I haven't got it to work reliably with ido-mode yet, which is a shame, but it's a lot better than nothing! :-)

南汐寒笙箫 2024-12-17 16:14:50

以下代码可能会有所帮助:

  (defun find-file-as-root ()
    "Find a file as root."
    (interactive)
    (let* ((parsed (when (tramp-tramp-file-p default-directory)
                     (coerce (tramp-dissect-file-name default-directory)
                             'list)))
           (default-directory
             (if parsed
                 (apply 'tramp-make-tramp-file-name
                        (append '("sudo" "root") (cddr parsed)))
               (tramp-make-tramp-file-name "sudo" "root" "localhost"
                                           default-directory))))
      (call-interactively 'find-file)))

我将其放在 .emacs 文件中,它似乎来自这里: http://atomized.org/2011/01/toggle- Between-root-non-root-in-emacs-with-tramp/

我没有广泛使用它,但似乎这是朝着正确方向迈出的一步。

The following code may help:

  (defun find-file-as-root ()
    "Find a file as root."
    (interactive)
    (let* ((parsed (when (tramp-tramp-file-p default-directory)
                     (coerce (tramp-dissect-file-name default-directory)
                             'list)))
           (default-directory
             (if parsed
                 (apply 'tramp-make-tramp-file-name
                        (append '("sudo" "root") (cddr parsed)))
               (tramp-make-tramp-file-name "sudo" "root" "localhost"
                                           default-directory))))
      (call-interactively 'find-file)))

I had it in my .emacs file, and it seems to come from here: http://atomized.org/2011/01/toggle-between-root-non-root-in-emacs-with-tramp/

I haven't used it extensively but it seems like that is a step in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文