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

Attachment: signature.asc
Description: PGP signature

Reply via email to