ssh through emacs shell?

27,319

Solution 1

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.

Solution 2

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 $ 

Solution 3

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.

Solution 4

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

Solution 5

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

For Reference: Open file via SSH and Sudo with Emacs

Share:
27,319
hatmatrix
Author by

hatmatrix

Updated on July 09, 2022

Comments

  • hatmatrix
    hatmatrix almost 2 years

    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
    hatmatrix over 14 years
    I'll have to check out this Tramp mode, sounds great. Thanks!
  • Dirk Eddelbuettel
    Dirk Eddelbuettel over 14 years
    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.
  • hatmatrix
    hatmatrix over 14 years
    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...
  • Hamza Yerlikaya
    Hamza Yerlikaya over 14 years
    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..)
  • hatmatrix
    hatmatrix over 14 years
    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
    hatmatrix over 14 years
    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
    hatmatrix over 14 years
    Wow, that looks pretty awesome. Emacs has two too many shell options!
  • yves Baumes
    yves Baumes about 11 years
    @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!!
  • Ehvince
    Ehvince almost 10 years
    and then we can find and edit files normally ! C-x C-f works, and some elisp like find-file too :) wikemacs.org/wiki/Eshell#Built-In_Commands
  • Gordon Gustafson
    Gordon Gustafson almost 10 years
    @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?
  • kevzettler
    kevzettler over 7 years
    This looks awesome but I'm getting an error Host name must not match method "ssh"
  • rorsach
    rorsach over 6 years
    On Windows, I use plink instead of ssh, like this /plink:user@remote-machine:/some/path. plink is a utility that comes with putty.