8

In Emacs, when I open the file /ssh:USER@HOST:/PATH, Tramp mode kicks in and everything is great. While editing the file, I want to open a remote shell as well using M-x shell, but its behaviour is just baffling. It seems to recognize I'm in Tramp mode (based on default-directory, I think), and it presents this prompt in the minibuffer:

Remote shell path: /ssh:USER@HOST:PATH//usr/local/bin/bash
                                      ^
                                      \-- Cursor here

The cursor is in the middle there, with the left part in grey and the right part in black. The right part is my local login shell. Now, if I press enter, it doesn't work. The buffer just has:

env: ‘/usr/local/bin/bash’: No such file or directory

The *Messages* seem to indicate nothing went wrong with the Tramp connection:

Tramp: Opening connection for USER@HOST using ssh...
Tramp: Sending command ‘exec ssh -q -l USER  -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none HOST’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘HOST’
Tramp: Opening connection for USER@HOST using ssh...done

I think I know what's happening. It's trying to run /usr/local/bin/bash on the remote server as the shell (which doesn't exist). If I manually change it to /ssh:USER@HOST:PATH/bin/bash, it works and I get a remote shell as I expect. Note that I have to remove the double slash, and I have to keep the ssh part; /ssh:USER@HOST:PATH//bin/bash doesn't work, nor does /bin/bash.

My question is, WHY does Emacs assume the remote machine has the same shell at the same path? Why can't it just use the login shell of my user on that machine, which is what I'd assume people want 99% of the time? Is there any configuration to fix this?

Some details about my environment:

  • macOS 10.12.6
  • emacs build (Homebrew): d12frosted/emacs-plus/emacs-plus: stable 25.3 (bottled), HEAD
  • using emacs -q, so no config
  • my login shell on the local machine is /usr/local/bin/bash
mk12
  • 181
  • 2

1 Answers1

3

Emacs / Tramp don't know your login shell. You could teach them, by setting

(setq explicit-shell-file-name "/bin/bash")

See also the discussion in the Emacs manual at (info "(emacs) Interactive Shell")

Michael Albinus
  • 6,647
  • 14
  • 20
  • 1
    But isn't it using ssh to connect to the remote machine? Maybe I'm not really understanding how shell/term work. How is the remote shell feature different from just opening a local shell in Emacs and then running `ssh USER@HOST` as the first command (which would use the login shell of the user on that machine)? – mk12 Nov 30 '17 at 18:17
  • 1
    Tramp uses always /bin/sh when going remote via ssh. So it doesn't know your login shell on the remote machine. – Michael Albinus Dec 01 '17 at 08:48