4

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
  • any solutions for this? – dangom Mar 21 '18 at 17:56
2

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")

  • 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 1 '17 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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