Using Emacs TRAMP with an ssh server that doesn't provide /bin/sh?
Asked Answered
O

2

9

I am trying to use Emacs TRAMP to access files over ssh on a server that does not provide /bin/sh, and so I get the following error when I try to connect:

env: can't execute '/bin/sh': No such file or directory

Is there any way to tell TRAMP where the remote shell is for that server? (The "server" is a tethered Android phone, so sh in at /system/bin/sh.)

Oeo answered 17/5, 2012 at 3:26 Comment(0)
A
6

See also the docstring for the tramp-methods variable. This part would appear noteworthy:

  • tramp-remote-shell
    This specifies the shell to use on the remote host. This MUST be a Bourne-like shell. It is normally not necessary to set this to any value other than "/bin/sh": Tramp wants to use a shell which groks tilde expansion, but it can search for it. Also note that "/bin/sh" exists on all Unixen, this might not be true for the value that you decide to use. You Have Been Warned.

Edit:

So here's a way you could create a new method based on an existing one ("scpc" in this example), and then give the custom method a different remote shell:

(require 'tramp)
(let* ((base-method (cdr (assoc "scpc" tramp-methods)))
       (new-method (copy-tree base-method))
       (rshell (assq 'tramp-remote-shell new-method)))
  (setcdr rshell "/system/bin/sh")
  (add-to-list 'tramp-methods (cons "android" new-method)))

Note that in Emacs 23 (Tramp 2.1.20), this property was named tramp-remote-sh. In Emacs 24 (Tramp 2.2.3-24.1) it has been changed to tramp-remote-shell.

And I'm guessing that you can use this method by default for your specified host with this:

(add-to-list
 'tramp-default-method-alist
 (list "\\`myhost\\'" nil "android"))
Antwanantwerp answered 17/5, 2012 at 3:41 Comment(5)
It looks like that sets the shell for all access via a given method (e.g. ssh). Is there any way to set this per-host?Oeo
You probably want to add a new method which uses the necessary tramp-remote-shell but is otherwise identical to the method you are basing it on, and then use that for accessing the host in question.Antwanantwerp
See also the tramp-default-method-alist variable, for mapping hosts to methods.Antwanantwerp
I'll probably end up adding a new method with the remote shell set.Oeo
I also have a problem with connecting with TRAMP over SSH to Android (2.2 on Samsung Galaxy S): not even with /bin/sh, but with "env" at an early stage -- bugs.launchpad.net/emacs/+bug/1041474 . Another problem to treat in a method devised for connecting to Android over SSH.Shornick
G
-1

ssh expects to use the remote user's login shell. If you have root access to the server, you can change the entry in the passwd file:

:blah:blah:user_name:blah:/path/to/shell

Or just symlink /bin/sh to it.

I don't believe there is any way to change this from the client's side, but if there is, you would need to tell ssh, not TRAMP. (You could do this via an ssh_config file.)

Edit: I stand corrected.

Gaius answered 17/5, 2012 at 3:32 Comment(1)
This is incorrect. @Antwanantwerp has explained it correctly; tramp uses the shell specified by tramp-remote-shell. It is also incorrect to say that you have to use ssh_config for anything like this as the program executing ssh can tell ssh which program to execute on the remote host on ssh's command line.Chamness

© 2022 - 2024 — McMap. All rights reserved.