1 Introduction

TRAMP is a package providing an abstraction layer that can be used for accessing remote files on
different machines. I say "abstraction layer" because it's not just a simple library for reading and
writing files, it hooks into Emacs at a low enough level that other packages need not be aware of it
in order to use it.

TRAMP stands for Transparent Remote (file) Access, Multiple Protocol

So what is this and how do I use it?

2 What's required to use TRAMP

While TRAMP is built in to Emacs, it does require some external tools, so if you can, install these:

If you also want to change the default username that tramp uses to connect, as by default it uses
your current username, you can change tramp-default-user and tramp-default-user-alist for that.

Finally, if you go to a remote host quite often, you can make it the default by setting
tramp-default-host or tramp-default-host-alist.

5 Editing remote files

Imagine you have a server remoteFoo and you want to edit a file in /etc/hosts, first you would
invoke find-files with C-x C-f, and then type:

/ssh:user@remoteFoo:/etc/hosts

Hit enter, and now you have a buffer that coordinates to this file. You can also leave out the
"user" part if you use the same user as your current username:

/ssh:remoteFoo:/etc/hosts

Whenever you save the file, tramp will transfer it back to the remote machine, you're technically
editing a buffer that is a local (temporary) file, which is being transferred back and forth as
needed by Emacs.

6 Troubleshooting

You can turn on tramp's logging by setting tramp-verbose to a number between 0 and 10 (inclusive),
the default value is 3, with increasing values being more and more verbose:

Value

Description

0

silent (no tramp messages at all)

1

errors

2

warnings

3

connection to remote hosts (default level)

4

activities

5

internal

6

sent and received strings

7

file caching

8

connection properties

9

test commands

10

traces (huge).

Sometimes you run into trouble with tramp, it hangs, or it can't connect to a machine, this can
especially happen if you forcibly disconnect the connection (like closing your laptop lid) while a
session is open, in that case, you might need to clean up tramp's internal accounting before opening
a new tramp session.

There are two "magic" cleanup commands:

tramp-cleanup-all-buffers

This kills all the remote buffers that tramp has around

tramp-cleanup-all-connections

Flushes all of tramp's internal things, like password, file, and connection caches, as well as
internal buffers.

6.1 Dealing with funky shells

Tramp does a pretty decent job of handling shells, but there are a couple of exceptions. The first
one is Fish, which is a non-posix shell, so it doesn't handle things as nicely. I haven't tested it
very much, so your mileage may vary.

The other issue is with prompts, tramp tries to figure out whether the connection is working by
issuing a couple of commands like ls and cd, but weird prompts can sometimes confuse it. If you
have a seriously crazy prompt, check out shell-prompt-pattern and tramp-shell-prompt-pattern if
you have any problems.

7 Editing local files as a different user

Have you ever accidentally opened a file as your user when in order to change it, you have to be
root? Tramp can help!

(defunedit-file-with-sudo()"Take the file currently being edited, and open it as root with `sudo'."(interactive)(let((file-name (buffer-file-name)))(when file-name
(find-alternate-file (concat "/sudo::" file-name)))))

This will re-open the buffer you're currently editing, but as root.

If you didn't want to be "root", but a different user, you could use the "su" method instead, with a
username, so C-x C-f and then:

/su:test@localhost:/home/test/hi

The "sudo" method might allow you to do this also, but "su" saves two whole characters!

8 SSH config magic

Now, it might not sound very efficient to make a connection, and in fact, it's not, this is why
tramp caches a bunch of things by using ssh options to keep a connection around. It does this when
tramp-use-ssh-controlmaster-options is set to "t", which it is by default.

Tramp will use things like ControlMaster, ControlPath, and ControlPersist to keep a connection
around for a certain time.

In some cases though, you don't want this, you want to use your configuration options. Things that
you stuck in ~/.ssh/config instead of tramps. If you set tramp-use-ssh-controlmaster-options to
"nil" it will use those options, here are the ones I recommend:

ControlMaster allows sharing multiple sessions over a single network connection, "auto" means to
try and use a master connection, or create one if it doesn't exist. This is what can speed up tramp.

ControlPath is the path for the socket user for the master control.

ControlPersist keeps the connection open for a certain amount of time, "0" or "yes" keeps it open
forever, while a number means the number of seconds before automatically closing it.

Usually then, I'll "persist" a connection by ssh-ing to the machine in a terminal or shell buffer,
and then tramp doesn't have to re-negotiate the connection every time I make a change to a buffer,
it just has to transfer the file.

9 Integrating with other parts of Emacs

Since tramp isn't just for editing files, there are a lot of really neat things you can do with it.
This isn't an exhaustive list, these are just the ones I use the most often.

The nice thing about this is that all of your typing is local, if it's a slow connection (or if
there is no connection because you've been disconnected), tramp only sends things over the network
when you hit RETURN, not when you press any key (like ssh does).

9.3 Magit

You can do everything you usually would with Magit, but over tramp on a remote machine! Either
invoke magit-status on a remote buffer (one you already opened with tramp), or manually with M-:
(magit-status "/ssh:ivalice:/home/hinmanm/es/elasticsearch") (or whatever location.)

9.4 Org-mode

Want do execute some org source blocks, but on a remote machine? You can!