42

I wonder if anyone out there uses ssh through the emacs shell. I am able to connect with the remote machine but I cannot open files to view/edit with emacs using 'emacs filename' as the 'Terminal type "dumb" is not powerful enough to run emacs' (normally emacs would open within the console when connecting through the terminal).

Is this a bad idea to try to use emacs in such a way, or is this possible with a few fixes? Thanks much!

hatmatrix
  • 42,883
  • 45
  • 137
  • 231

6 Answers6

45

It may not be obvious on first sight, but eshell, the shell that is implemented in Emacs Lisp works fine with tramp:

Welcome to the Emacs shell

~ $ uname -a
Linux local-machine 2.6.30-1-686 #1 SMP Thu Jul 30 14:45:30 UTC 2009 i686 GNU/Linux
~ $ cd /ssh:user@remote-machine:~
/ssh:user@remote-machine:/home/user $ uname -a
Linux remote-machine 2.6.18-6-686 #1 SMP Thu Aug 20 21:56:59 UTC 2009 i686 GNU/Linux
/ssh:user@remote-machine:/home/user $ 
hillu
  • 9,423
  • 4
  • 26
  • 30
  • 1
    Wow, that looks pretty awesome. Emacs has two too many shell options! – hatmatrix Sep 10 '09 at 19:43
  • 2
    @hillu I am just ... stucked on my chair! Right now, i was using tramp for accessing remote files for only an hour or so. Thank to your post I've launched eshell which placed me directly "into" the remote machine. And you know what? you may even copy files from one machine to the other as easily as invoking a ```cp``` command. A.W.E.S.O.M.E!! – yves Baumes Feb 17 '13 at 22:33
  • 2
    and then we can find and edit files normally ! `C-x C-f` works, and some elisp like `find-file` too :) http://wikemacs.org/wiki/Eshell#Built-In_Commands – Ehvince May 11 '14 at 20:35
  • 1
    @yvesBaumes and @hillu, does `cd` work properly for you with this method? For me `cd ..` won't take me above my home directory if that's where I originally `cd` to, and `cd /` takes me to my local root. Do you know of any tips to help eshell `cd` from getting confused like this? – Gordon Gustafson May 27 '14 at 21:30
  • This looks awesome but I'm getting an error `Host name must not match method "ssh"` – kevzettler Jan 28 '17 at 01:47
  • 1
    On Windows, I use *plink* instead of *ssh*, like this `/plink:user@remote-machine:/some/path`. *plink* is a utility that comes with *putty*. – rorsach Dec 29 '17 at 19:52
18

A couple of ideas

  • Source the .bashrc explicitly via . ~/.bashrc and/or rearrange your bash init files and ~/.profile so that this gets loaded inside the emacs shell; then running ssh inside the Emacs shell works just fine
  • Use the emacs-specific Tramp mode to access remote files via ssh inside your local Emacs -- this is useful if you just need to update/touch/edit a remote file so you would not need to open a remote emacs inside the ssh session started from inside your local emacs.
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • I'll have to check out this Tramp mode, sounds great. Thanks! – hatmatrix Aug 29 '09 at 03:33
  • 1
    Yes -- the other questioner beat me to the first reply by a minute or two but tramp is what you're after if you just want to quickly edit a file or two other host. It simple copies it to your machine and sends updates versions back via scp -- without you having to do it explicitly. That can be much more leightweight than export an X11 session (which he rightly pointed out as another option). Also, tramp is very much the follow-up to the older ange ftp he mentioned. – Dirk Eddelbuettel Aug 29 '09 at 15:11
  • Yes, I noticed that tramp supercedes ange ftp (according to other threads). And my X11 connections seem to be terribly slow so tramp is definitely better for my situation. Thank you. – hatmatrix Aug 31 '09 at 21:49
  • My pleasure. If you think that's the right answer I guess you could also accept it as the official answer :-) – Dirk Eddelbuettel Sep 01 '09 at 01:38
17

Emacs has term-mode which is full blown terminal emulator you can run emacs in emacs. Anything you run on terminal will run in term-mode

Also emacs has tramp mode which can open files through ssh.


/scp:user@ipOrHost#port:/

it will transfer files back and forth. you just edit them as you would edit local files.

No need for x11 forwarding or other shenanigans.

Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
  • Thanks - there seem to be many options: shell, eshell, and term... which one do you prefer? I've googled a bit and it seemed that 'shell' was the most widely used... – hatmatrix Aug 30 '09 at 01:44
  • shell and eshell despite their names are not real shells. they just read and write to a process. but term on the other hand is an terminal emulator just like terminal on osx or xterm on linux. you can even run ncurses stuff in it which you can not do in shell. use term if you want to live in emacs and use shell if you want to run quick commands and still use a terminal ( xterm etc..) – Hamza Yerlikaya Aug 30 '09 at 09:35
  • 2
    Ah, yes - there seems to be some griping about term not having the documentation that shell and eshell does but it does appear to handle my ssh session better than shell... but emacs within emacs? "emacs: Terminal type eterm-color is not defined." says something about having to change the TERM variable, but if I read up on it more I suppose that it can be done? Scary! – hatmatrix Aug 31 '09 at 21:51
6

You could use ssh x forwarding to run a remote emacs and display it on the local computer.
I use Xming X Server when I'm on Windows

You could mount the remote filesystem with ssh and open the locally as normally.
For this I use ExpanDrive (commercial app) when on Windows

You could use emacs Ange ftp over ssh it can open remote files over ftp and ssh.
I use this with cygwin when on Windows

Nifle
  • 11,745
  • 10
  • 75
  • 100
1

I have been struggling with Xming, which works, but as my internet connection is not the fastest I have to wait more 30 seconds before emacs or any X app even shows up. Also scrolling through a buffer after it has been opened will freeze from time to time => Very annoying

Try No machine (nxserver-freenx server/client). There are free edition servers, absolute the best and fastest solution when you want to connect to a Linux box and use xterm and emacs over X. It shows up immediately and responds so fast. Even over a really slow connection :-) Clients are available for Windows, Mac OS, Linux

Darkosa
  • 55
  • 7
1

Emacs option for ssh : c-x c-f /ssh:user@host:/home/path/

For Reference: Open file via SSH and Sudo with Emacs

FeLiX StEpHeN
  • 111
  • 2
  • 8