I really like the emacs terminal but each time I use it to log into my server. I don't know how to use emacs to edit files on the server.

Or it is not possible to do it? I can only edit files on server via ssh edit? However, in the latter case, how can I edit file as root user?


There is Tramp. You can edit a file on another machine using the syntax /ssh:user@machine:/path/to/file. If you take sudo instead of ssh, and empty user and machine, you can edit a local file as root. Like /sudo::/path/to/file.

| improve this answer | |
  • Thanks for your reply. My question is how can I use sudo when I want to edit files on the server. – LifeWorks Mar 31 '16 at 16:22
  • @LifeWorks multi hop? – npostavs Mar 31 '16 at 17:24
  • 2
    Yes, mutihop. /ssh:user@machine|sudo:machine:/path/to/file let you edit files with root credentials on the other machine, after first login as user. – Michael Albinus Mar 31 '16 at 18:50
  • There are several more examples of editing local and remote files as sudo in the tramp help screens in emacs (C-h i and look under Tramp, Multi-hops). Enter them directly as Michael Albinus shows in his response or setup defaults using the link that npostavs provided. – Emacs User Apr 1 '16 at 0:19
  • I tried with @Mi – ychaouche Sep 23 '19 at 11:08

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.