【问题标题】:Trouble with Emacs Tramp when trying to sudo access remote file尝试 sudo 访问远程文件时出现 Emacs Tramp 问题
【发布时间】:2018-08-02 21:00:23
【问题描述】:

在 Emacs25 中,我使用推荐的语法以 sudo 模式打开远程文件:

find-file "/ssh:ichiban@izu|sudo:ichiban@izu:~/

但 Emacs 只是挂起。我在 .emacs 文件中设置了一些调试设置:

(require 'tramp)
;(setq tramp-debug-buffer t)
(setq tramp-verbose 10)

; to enable tracing in tramp
(require 'trace)
(dolist (elt (all-completions "tramp-" obarray 'functionp))
  (trace-function-background (intern elt)))
(untrace-function 'tramp-read-passwd)
(untrace-function 'tramp-gw-basic-authentication)

但结果信息无济于事。

要查看该信息,我从终端启动 Emacs,然后在终端挂起时向其发送 Ctrl-c(不返回)- 然后我可以读取调试数据。

没有 sudo 模式也可以正常工作:

find-file "/ssh:ichiban@izu:~/

我想了解有关 Emacs 使用的协议的更多详细信息,并了解如何调整该协议 - 任何想法都将不胜感激。

这是“sudo”和“non sudo”情况的调试输出不同的地方:

失败:sudo 案例 /ssh:ichiban@izu|sudo:ichiban@izu:/home/ichiban

15:12:54.224210 tramp-maybe-open-connection (3) # Opening connection for ichiban@izu using sudo...
15:12:54.240334 tramp-get-local-locale (7) # locale en_US.utf8
15:12:54.240731 tramp-compute-multi-hops (5) # Add proxy ("izu" "ichiban" "/ssh:ichiban@izu:")
15:13:08.214197 tramp-maybe-open-connection (3) # Opening connection for ichiban@izu using sudo...failed

成功:非 sudo 案例 /ssh:ichiban@izu:/home/ichiban

15:02:58.629883 tramp-maybe-open-connection (3) # Opening connection for ichiban@izu using ssh...
15:02:58.647868 tramp-get-local-locale (7) # locale en_US.utf8
15:02:58.648444 tramp-get-connection-property (7) # login-args undef
15:02:58.648777 tramp-get-connection-property (7) # login-args undef
15:02:58.649111 tramp-call-process (6) # ‘ssh -o ControlMaster’ nil  *temp*
15:02:58.651325 tramp-call-process (6) # 255
command-line line 0: missing argument.
15:02:58.651640 tramp-call-process (6) # ‘ssh -o ControlPath=%C 0.0.0.1’ nil  *temp*
15:02:58.655076 tramp-call-process (6) # 255
Pseudo-terminal will not be allocated because stdin is not a terminal.

【问题讨论】:

    标签: emacs sudo tramp


    【解决方案1】:
    find-file "/ssh:ichiban@izu|sudo:ichiban@izu:~/
    

    您几乎肯定想使用:

    find-file "/ssh:ichiban@izu|sudo:root@izu:~/
    

    或等效(因为 root 是此方法的默认用户)或更短:

    find-file "/ssh:ichiban@izu|sudo:izu:~/
    

    我会冒险猜测 Emacs 挂起,因为 tramp 处于无限循环中,试图解析你给它的代理——你告诉它在访问文件时使用代理 /ssh:ichiban@izu: ichiban@izu!

    M-x report-emacs-bug 建议添加一些循环检测来防止这种情况发生。

    【讨论】:

    • 这里指定:[emacswiki.org/emacs/TrampMode#toc18],我使用的语法是:[Cx Cf /ssh:you@remotehost|sudo:them@remotehost:/path/to/file RET],除了“他们”就是“你”。在操作方面,1:[connect to ichiban@izu via ssh],然后 2:[elevate ichiban to sudo]。我会试试你的建议。
    • 好的,它有效!我输入的密码是ichiban的密码,而不是root的,这正是我想要的。非常感谢。
    • 不客气。请注意,tramp 语法很像在 shell 中使用 sudo 命令:/sudo:root@host 就像运行 sudo -u root <command>,与仅运行 sudo <command> 相同。因此,您最初的尝试相当于首先以 ichiban 登录,然后以用户 ichiban 的身份发出 shell 命令 sudo -u ichiban <command> 以运行 <command>,尽管已经以该用户身份登录。
    猜你喜欢
    • 2013-10-17
    • 2015-04-10
    • 1970-01-01
    • 2011-10-03
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    相关资源
    最近更新 更多