Search code examples
emacssudotramp

Trouble with Emacs Tramp when trying to sudo access remote file


In Emacs25 I used the recommended syntax to open a remote file in sudo mode:

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

but Emacs just hangs. I set some degging settings in my .emacs file:

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

but the resultant information is no help.

To see that information I start Emacs from a terminal and then send it a Ctrl-c (without a return) from the terminal when it hangs - then I can read the debug data.

Without sudo mode it works fine:

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

I'd like to see more detail about the protocol Emacs is using and also learn how to tweak that protocol - any ideas would be appreciated.

This is where the debug outputs for the "sudo" and "non sudo" cases differ:

fail: sudo case /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

succcess :non sudo case /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.

Solution

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

    You almost certainly wanted to use:

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

    or equivalently (as root is the default user for this method) and shorter:

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

    I'm going to hazard a guess that Emacs was hanging because tramp was in an infinite loop trying to resolve the proxy you'd given it -- you'd told it to use the proxy /ssh:ichiban@izu: when accessing files as ichiban@izu!

    Please M-x report-emacs-bug to suggest that some cycle detection is added to protect against this.