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

Tilmann Singer <[email protected]> Sun, 20 Apr 2025 18:36:03 +0200
Newsgroups gmane.emacs.tramp
Message-ID <[email protected]>
Hi,

I want to connect to a host with ssh, sudo to another user, then run a
shell command as this user. The user being sudo-ed to has a ~/.profile
which needs to be sourced to set up the correct PATH.

How can I invoke Tramp so that it starts a login shell, e.g. with `sudo
-i`, or so that it sources the ~/.profile through some other mechanism?

The following sequence (with `env` for testing) does not source
~/.profile, because, as I understand it, the final sudo starts a shell
with `/bin/sh` by default:

C-x C-f /ssh:example.com|sudo:[email protected]: RET M-& env RET

With this variation, the ~/.profile is sourced as desired:

C-x C-f /ssh:example.com|sudo:[email protected]: RET M-& sh -l -c env RET

but I would prefer not having to do anything special as part of the
command itself, rather have Tramp prepare the session entirely. My final
goal is to use this in an org-babel code block, and it would be more
flexible and elegant not having to use a connection-specific variant of
the command.

The help for the `tramp-methods` variable mentions the
‘tramp-remote-shell-login’ param, which is already set to "-l" for the
sudo method, so that might do the trick – under which circumstances does
Tramp use this param?


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

iQJCBAEBCAAsFiEEXoajwlwFeMDQ1WTwuGOMJcql3BYFAmgFInMOHHRpbHNAdGls
cy5uZXQACgkQuGOMJcql3Ba9Yw//exQtEBVilvG3Ls61VUD8FhiNEoyMsHQCMRnL
Cp2oYZduUW4rQm/AdGE/SXkAv8+BOAp3sWYRMZDGkGGvkiIQFdvjiLog6oiaxCFg
vPOGlyoYFumvlbSguji0icmEHc0tauzg8y7rmDjLUO4LPBQ1jITJbo0n7kH+6DVb
xx/11Imz1KAyS1lcuIAzoXSUhfUdyy5pb6l7mlQvGRYHvUDmxoP4lH0hbhls3Gyz
b/VmzWLgOBvaxaKx3XC5rKjspXeIi/ZrDfcWnOECXNoXgSYknuBDrcJOML1REF2T
6Vyp3QLvDJ9cdGxcxWwCDysd2g4TqeY2S0CbgtWlqXZEWSkyNyY/15098bI2Rd+2
PI910gAvDo2Nd2/JEZ1z+P38zqNNnqmYJ3pHTTFl8396YYo8awYkE7kC++v3ESE1
mYR7sQZ0kFl4HdEfQFF5nrFB7US452+LNNxST152z0IfXoOI9g6MtNs9ZyuEpHSz
A6yGUp/mtIQEde2vQ70CC+aT4Aag919aSbV5+AT3SP5syjfJ2/gSVjSVbGKZchnt
qqtsxrZermyY7IyT9X4049VvNOTp4gbu2mE5oKmQwx4nJNVDFna2xmiPoTdC523I
mYJf3gwAW145P+G4I1MB2Mlo3ZXNsNyEW4nTsBphpL6dbFK/MKUzZdrVSghr/5vi
lNXpg98=
=lxbL
-----END PGP SIGNATURE-----