Not being very LISP-literate, I am having trouble figuring out from the documentation here how to set up a shortcut to allow me to edit a remote file as root.

I've successfully set up an ssh-config file to allow pretty low-overhead entry for remote editing (see this question for the background), and would like a similar approach for editing remotely as root.


Tramp remembers your settings over a session. Open one time /ssh:host|sudo:host:/path/to/file. From now on, Tramp knows that it needs an ssh connection prior to sudo for that host, and you can symply use /sudo:host:/path/to/file. With all abbreviations discussed the other question.

  • rogerl: Note also that Tramp adds the appropriate entry to tramp-default-proxies-alist when you use this ad-hoc multi-hop syntax (where the | is separating each hop), and so you can inspect the variable afterwards to see what has been added to it. See also stackoverflow.com/a/16408592
    – phils
    Apr 22 '16 at 5:55
  • I just found this answer, and it works great...except that I have hostname shorthand defined in an .ssh/config file. When I type /sudo:hostname:/etc/hosts, I get what you would expect, but when I type /sudo:abbrev:/etc/hosts, I get the message "Host abbrev looks like a remote host, sudo can only use the local host". There is a longer (somewhat) discussion of my problem in the comments to the accepted answer of he thread quoted in the previous comment here.
    – rogerl
    May 14 '16 at 2:15

I follow Michael Albinus advice for long paths. Tramp remembers the hosts and protocols and you can use Tramp's built-in completion to speed up revisiting the same remote files. However, for some long files that I edit every now and then, I setup a bookmark using Emacs's bookmarks.

While in the remote editing buffer, I bookmark the remote Tramp location with:

C-x r m 

Later when I need to get back to that location, I list all bookmarks with:

C-x r l

Then select the file I want to edit. I like this approach for two other reasons. Bookmarks is a built-in feature and no need for installing additional packages. The second reason is that now I can copy that bookmark file to other machines as needed. I actually sync it to many machines so I have the same bookmarks no matter which machine I'm currently using.

If you have lots of remote files to edit, you can look into editing bookmark files directly. You can also use sorting and filtering options, in case you want to group the bookmarks by location/task/machine/etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.