If I locally call async-shell-command it takes the shell from shell-file-name (/bin/bash).

However if I use su or ssh via tramp to invoke a shell command remotely it always runs as /bin/sh. The default shell on the remote box is bash.

This is not the case if run an interactive M-x shell where the correct bash shell is always used, both remotely and locally.

My config looks like:

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

I'm using emacs 25.3

Any ideas how to make bash the default shell when running shell commands via tramp?

  • the easiest way would have been logging into sh via tramp, then entering bash <enter> or running remote scripts with a shebang requiring bash at the top. I know, not exactly automated/convenient, but fast.
    – user17303
    Oct 24, 2017 at 22:06

1 Answer 1


tramp-handle-shell-command carries the comment

;; We cannot use `shell-file-name' and `shell-command-switch',
;; they are variables of the local host.

Instead, it uses the arguments tramp-remote-shell and tramp-remote-shell-args from the variable tramp-methods. You can override them by tweaking tramp-connection-properties, the Tramp manual discusses exactly the given case in the section Setting own connection related information:

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "/ssh:[email protected]:")
                   "remote-shell" "/bin/ksh"))
(add-to-list 'tramp-connection-properties
             (list (regexp-quote "/ssh:[email protected]:")
                   "remote-shell-login" '("-")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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