Contact Sales Sitemap Customer Login

HOWTO: Edit Files Remotely with Emacs

If you are doing web development, it is very useful to be able to make changes to files remotely and then test the changes immediately. You could start an editor on the remote server and do it that way, but you are probably more comfortable on your local workstation and would like to be able to do it from there. Emacs has the ability to do this with a mode called tramp. The best place to get Emacs for windows is from Setting this up takes a few steps, but once it's done it will be well worth it.

Download and and

You will use PuttyGen to generate your ssh keys. In the Key menu choose SSH-2 dsa key. It will create a public and private key, which you will save with buttons labeled for that purpose. When it asks if you want to store the private key without a passphrase, select Yes unless you want to enter a password each time you use it. The filename of the private key will have a .ppk suffix. This is the one that is loaded into pageant. After you have started pageant, click its icon in the task bar and it will open a window with an option to add your private key.

To have pageant start when you boot, put a shortcut to it in your Startup folder in the Start menu. By modifying the properties of the shortcut you can also have it load your private key automatically.

Put the public key into the home directory of your remote user in a file /home/username/.ssh/authorized_keys2. The permissions of the .ssh directory need to be 700.

Read the full documentation at and if you need help using Pageant and PuttyGen to create and hold your ssh keys.

Add the directory that contains plink.exe to your PATH environment variable. The PATH variable is in the form of directory names separated by semicolons. You can see your environment variables by going to the control panel and choosing System. Click the Advanced tab and you will see a button called Environment Variables which lets you edit the values or add new ones.

In your home directory on Windows, create a file called '.emacs' and a directory called '.emacs.d'. Your home directory is the one contained in the HOME environment variable. In your .emacs file, put the following contents:

(add-to-list 'load-path "C:/Documents and Settings/username/.emacs.d/tramp/lisp")
(require 'tramp)
(setq tramp-default-method "plink")

In the example above, C:/Documents and Settings/username is the home directory, so customize this for your own system. Notice the forward slashes instead of the usual Windows backslashes. This is how pathnames are handled in Emacs.

Get the most recent version of tramp from The file will be in tar.gz format, so you will need a program to extract it. I recommend 7-zip, available from Extract the tramp archive into the .emacs.d directory.

Opening files in Emacs is done with the keystrokes Ctrl-x Ctrl-f and then typing in the name of the file to be edited. Usually you'll just enter the name of a file on your local filesystem, but with tramp you'll enter '/user@remotehost:path/to/filename'. Notice there is a slash at the very beginning. This lets emacs know that you'll be using tramp. Saving files with tramp is the same as locally, with the keystrokes Ctrl-x Ctrl-s.

I hope you find this information useful. Personally once I began using this I find that it's hard to use anything else for any extended period of editing.

Retrieved from ""
Recent Changes | RSS RSS Feed