9

我正在尝试使用 Emacs TRAMP 在不提供的服务器上通过 ssh 访问文件/bin/sh,因此在尝试连接时出现以下错误:

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

有什么方法可以告诉 TRAMP 该服务器的远程外壳在哪里?(“服务器”是一个绑定的 Android 手机,所以请在 sh in /system/bin/sh。)

4

2 回答 2

6

另请参阅tramp-methods变量的文档字符串。这部分似乎值得注意:

  • tramp-remote-shell
    这指定要在远程主机上使用的 shell。这必须是类似 Bourne 的外壳。通常不需要将其设置为“/bin/sh”以外的任何值:Tramp 想要使用一个能够理解波浪号扩展的 shell,但它可以搜索它。另请注意,所有 Unixen 上都存在“/bin/sh”,对于您决定使用的值,这可能不是真的。你被警告了。

编辑:

所以这里有一种方法可以基于现有方法(本例中为“scpc”)创建新方法,然后为自定义方法提供不同的远程 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)))

请注意,在 Emacs 23 (Tramp 2.1.20) 中,此属性被命名为tramp-remote-sh. 在 Emacs 24 (Tramp 2.2.3-24.1) 中,它已更改为tramp-remote-shell.

我猜你可以默认为你指定的主机使用这个方法:

(add-to-list
 'tramp-default-method-alist
 (list "\\`myhost\\'" nil "android"))
于 2012-05-17T03:41:37.507 回答
-1

ssh 期望使用远程用户的登录 shell。如果您对服务器具有 root 访问权限,则可以更改 passwd 文件中的条目:

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

或者只是符号链接 /bin/sh 到它。

我不相信有任何方法可以从客户端改变这一点,但如果有的话,你需要告诉ssh,而不是 TRAMP。(您可以通过 ssh_config 文件执行此操作。)

编辑:我的立场是正确的。

于 2012-05-17T03:32:42.017 回答