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?
Add a comment |
1 Answer
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.
3 Comments
phils
Nice. May I suggest that you also
M-x report-emacs-bug to propose this as a new standard method?P. B.
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.Michael Albinus
Please write the report. I'll add this feature happily to the next Tramp version.