Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to use the emacs installed my local computer to access remote files I have in a remote server? I have googled and found out that I should use TrampMode however it is necessary for me to know the exact file path. Isn't there a way for me to open an ssh connection to the remote server and from there open the files with the local emacs in my computer?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

There are various ways to do this, but in generally you are going about this problem backwards. Copy your emacs configs to the remote machine and use emacs local to the files you are editing.

The "various ways to do this" would fall into two categories. First would be ways of mounting a remote drive locally through something like sshfs, some fuse file system, samba, nfs, or any number of other mounting systems to bring file level access to your machine. Second would be various programs that allow you to login and browse a remote system, then operate on files by transferring a copy of them to a local temp file, editing it, then transferring it back. Several programs make that process look pretty seamless, but it's a hack.

share|improve this answer
1  
thanks, sshfs was what I needed –  starcorn Apr 20 '11 at 10:02
1  
“Several programs make that process look pretty seamless, but it's a hack.”: That's what Tramp (which ships with Emacs nowadays) is about. It's not a hack, it's a natural way of working with remote files. –  Gilles Apr 20 '11 at 21:20
    
@Gilles: I know nothing of Tramp, so my "hack" alegation must needs not apply. I was particularly thinking of various file manager programs that have menu items like "open in an editor". While these to work to get a file open, they are typically brittle in the way they require the file being copied, modified, copied back, etc. Intermediate file saves before the editor closes are often not pushed upstream making them an awkward way to work on files. If you know a way around the limitations in Tramp @starcorn complained of by all means add another answer! –  Caleb Apr 20 '11 at 21:29
1  
With Tramp, the editor is doing the work, so it knows to push when saving and so on. The ideal solution would be to make emacsserver and ssh interoperate, but that's hard. The two workarounds I would have offered are sshfs and eshell, both mentioned already. –  Gilles Apr 20 '11 at 21:35

I do think that Tramp is what you are looking for. You can use Dired mode to browse the remote directories and look for the file you want.

For example, if I'm looking for some file in /etc/ on a remote machine rem, I'd do the following:

  • Open emacs
  • hit C-x C-f
  • remove the path already present
  • type /rem:/etc/ and hit enter.

You'll get an output like this:

/ssh:rem:/etc:
total 1460
drwxr-xr-x 141 root root    12288 Aug 12 06:46 .
drwxr-xr-x  23 root root     4096 Jul 18 23:48 ..
drwx------   6 root root     4096 Nov 17  2009 .bzr
-rw-------   1 root root      749 Jul 18 23:30 .bzrignore
-rwx------   1 root root    10015 Aug 12 09:17 .etckeeper
drwxr-xr-x   3 root root     4096 Aug  6 00:47 .java
-rw-------   1 root root        0 Nov 17  2009 .pwd.lock

Then you can use e.g. the arrow keys to find the file you wanted to edit. Hit enter when the cursor is on the file to edit it.

share|improve this answer

Or you can open emacs, run eshell, then cd to the remote machine, like:

cd /hostname:~

Now, run shell commands, navigate to the file you want and open it:

find-file filename
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.