Re: How to tell tramp to use login shell in sudo multihop?

Tilmann Singer <[email protected]> Thu, 24 Apr 2025 22:19:41 +0200
Newsgroups gmane.emacs.tramp
Message-ID <[email protected]>
Tim Landscheidt <[email protected]> writes:
> I don't know if it fits your use case, but there is also
> tramp-remote-process-environment which can be used to set
> environment variables on (all) remotes.

Thanks. Unfortunately it is not sufficient for my use case because the
setup on each host varies.

I was hoping that it is possible to add a new custom tramp method, e.g.
called "sudoi", and after some dabbling around came up with this:

#+begin_src elisp :results none
(add-to-list 'tramp-methods
             '("sudoi" (tramp-login-program "env")
              (tramp-login-args
               (("sudo")
                ("-u" "%u") ("-i") ("%l")))
              (tramp-remote-shell "/bin/sh")
              (tramp-remote-shell-args ("-c"))))
#+end_src

which is a stripped copy of the entry for "sudo" with the sudo option
"-c" replaced by "-i". Now this remote path:

/ssh:example.com|sudoi:[email protected]:

sources the remote profile. Not sure if 'tramp-methods was meant to be
extended this way, but it works for me so far. And it has the benefit
that when the configuration is not present, it will fail right away with
the message "Method ‘sudoi’ is not known".


cheers, Til
signature.asc (application/pgp-signature, 853 B)
-----BEGIN PGP SIGNATURE-----

iQJCBAEBCAAsFiEEXoajwlwFeMDQ1WTwuGOMJcql3BYFAmgKnN0OHHRpbHNAdGls
cy5uZXQACgkQuGOMJcql3BYGfA//a7gmF/Rjj5KWWZF7sHPYLcy7eiWGLcf9q/8D
b/ZK8PCBwprl1VUGyB1HeEbcX1icaUX5WW5SWZvs39seSPgo99xXJLHfgQPTjbEL
97MifhAIBtuBz0xf0E0KDBEIJBOjPHsmnuPb3RbmpSo8k9zUODNCAJ/cEgnXvzpt
zUM/hbhylV6kBS6JXTAIekgK9evEUBiaHeU+lWBVxnmdiZMGjvBTw3VuRv2bh0Id
0yFKN9EY7fiEn2BQRkHZifTfwn3ps1ffx30Nn5JnVvb0t066hTprKKYawsvRM3+t
blsZlGhtcB4D5bkU3oo2ktPNr8zmQ3ZH+USffAVhnWWAfbbaEJKI0xnwTRxhJsAl
IN1pGVB6at3yNkUW7vu9F2Xn9Craz/5ZT7QqNku0gtpLK99jetNSuPJZnWuKP0QT
6heTuVX2ulJHEP/8TaJTF4Tv7y6cYx9L83iB2Bhz+vjTP9R1pN8KramoUEYeDKiZ
xZ1kZcM4cuXYUZtjZiD1kielbwsbp69BTRkvoQrP6Cl1w5QHa709m1AKTNQ7kMUv
R8ALtj4ZfXsNS7cPEvztDG+Q3rEkjCS+2BUxdTf+HMV3DFC2I8e9H5VCgaCRm3Bc
j4JBcV/8VZE3RGixEJtAJAiZCYIouokCpkolCLeoGiFg8kCJjlQL1evZdeOujZrA
lBbuxHo=
=xBNV
-----END PGP SIGNATURE-----