1

I think what I'm looking for may be a solution similar to multi hop with SSH and su; but instead of su, I have to use sg. The use case is that I have a user on a server, and the user belongs to multiple groups (main group ID group_A, second group ID group_B) for administrative reasons. SELinux Access Control is used so even if a directory is owned by me, but if my main group ID is not right, I will not be able to create files. In an interactive session, I would do chgrp group_B to switch my main group, and a new shell session will be created. If remotely launching a program, I would do ssh foo.com 'sg group_B /path/to/executable'. How do I achieve these effect in Emacs/Tramp?

1 Answer 1

2

I realized that ssh, su, etc. are defined in tramp-methods, which one can customize as follows to add another connection method called sg:

(eval-after-load 'tramp '(add-to-list 'tramp-methods '("sg" (tramp-login-program "sg") (tramp-login-args (("-") ("%u"))) (tramp-remote-shell "/bin/sh") (tramp-remote-shell-args ("-c"))))) 

Then one can do

C-x C-f /ssh:myuser@remotehost|sg:group_B@remotehost:/path/to/file 

to connect through multi-hops to remotehost as myuser using ssh and then switch main group from group_A to group_B using sg.

Sign up to request clarification or add additional context in comments.

3 Comments

Nice. May I suggest that you also M-x report-emacs-bug to propose this as a new standard method?
Will do. I've also modified the answer to use eval-after-load since Tramp is autoloaded and so tramp-methods is undefined before the first usage.
Please write the report. I'll add this feature happily to the next Tramp version.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.