# Opening Remote Files In Emacs Using SSH

## Beginning

For some strange reason, the emacs wiki page on tramp mode doesn't have instructions on how to open a file on a remote machine using tramp in its main section. You instead have to go down to the Tips and Tricks and try and pick out a version that works. So I'm writing this here so I maybe won't have to do all the searching I did the next time. This is the version that worked for me (Emacs 27.0.50, Ubuntu 19.04).

## Middle

### Editing a Remote User File

You start by opening the file like you would a local file (C-x C-f) and then in when the minibuffer opens up you use this syntax for the path:

/ssh:<username>@<hostname>>:<path to file>


So, for example, I have an SSH alias to hades@erebus named Hades and if I wanted to edit the emacs init file on that machine I would use this:

/ssh:Hades:.emacs.d/init.el


### Editing a Remote File As Root

To open a file as root you stick an extra pipe (|sudo) into the previous path syntax.

/ssh:<username>@<hostname>|sudo:<hostname>:<path to file>


This syntax doesn't work with SSH aliases (or didn't seem to when I tried), so editing the /etc/apt/sources.list file the same machine as before would use this:

/ssh:hades@erebus|sudo:erebus:/etc/apt/sources.list


## End

I got the sudo version from Stack Overflow (of course).