在 Emacs 中使用 su/sudo 打开文件 [英] Open a file with su/sudo inside Emacs
问题描述
假设我想在现有的 Emacs 会话中使用 su
或 sudo
打开一个文件,而不需要进入 shell 并执行 sudoedit
或 sudo emacs
.一种方法是
Suppose I want to open a file in an existing Emacs session using su
or sudo
, without dropping down to a shell and doing sudoedit
or sudo emacs
. One way to do this is
C-x C-f /sudo::/path/to/file
但这需要昂贵的通过SSH往返.有没有更直接的方法?
but this requires an expensive round-trip through SSH. Is there a more direct way?
@JBB 是对的.我希望能够调用 su
/sudo
来保存和打开.保存时重新授权是可以的(但并不理想).我正在寻找的是 find-file
和 save-buffer
的变体,它们可以通过 su
/sudo 进行管道传输"
.
@JBB is right. I want to be able to invoke su
/sudo
to save as well as open. It would be OK (but not ideal) to re-authorize when saving. What I'm looking for is variations of find-file
and save-buffer
that can be "piped" through su
/sudo
.
推荐答案
Tramp 的好处在于,您只需在打开第一个文件时支付到 SSH 的往返费用.然后 Sudo 会缓存您的凭据,Emacs 会保存一个句柄,以便后续 sudo 打开的文件花费更少的时间.
The nice thing about Tramp is that you only pay for that round-trip to SSH when you open the first file. Sudo then caches your credentials, and Emacs saves a handle, so that subsequent sudo-opened files take much less time.
我也没有找到节省负担所需的额外时间.够快了,海事组织.
I haven't found the extra time it takes to save burdening, either. It's fast enough, IMO.
这篇关于在 Emacs 中使用 su/sudo 打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!