Praveen's Blog

An Eternal Quest for Incremental Improvement

Remote file editing on GNU Emacs using TRAMP

I have been using GNU Emacs for programming for nearly 9 years now. It is exciting to keep discovering new extensions to Emacs throughout. I have heard of Ange-FTP before that can be used for remote file editing using FTP. However, I have never tried remote file editing on a local Emacs session. In most of the scenarios, I was dealing with editing files on the remote machines by invoking Emacs locally on those machines. But this time, I felt that invoking GNU Emacs (22) on my tiny VPS would be an overkill. So, I decided to try out remote file editing from a local Emacs session.

Even though I knew that I can do this with AgneFTP, I didn't really care to read the info about it as I don't run FTP on my server. The first hit on Google when I searched about remote file editing on Emacs was TRAMP (Transparent Remote [file] Access, Multiple Protocol). I am using GNU Emacs 23 trunk snapshot. TRAMP is included by default in GNU Emacs 22+. Configuration of TRAMP was quite simple. I had to load the module and set the protocol for remote access. Just a two liner in my .emacs did the trick.

(require 'tramp)
(add-to-list 'tramp-default-method-alist '("praveen.kumar.in" "" "ssh"))

The three entries for tramp-default-method-alist element are host, user and protocol. You can fill in the host, the user or both. Another interesting use of TRAMP is editing files as root on local machine. This can be quite handy as well. Take a look at TRAMP user guide for full configuration options. Once I added these lines, I was able to open /home/praveen/.bashrc on my server using the file name as /praveen.kumar.in:~/.bashrc in the normal find-file (C-x C-f) function. Happy remote editing!


Comments