Thursday, 1 March 2018

shell - Reload a Linux user's group assignments without logging out


When assigning a user's secondary group list using:


# usermod -G  

is it possible to force this group assignment to take effect without logging out all running sessions?


This would be very useful in the situation where a Screen session exists with many running shells, as the entire session essentially needs to be destroyed to make the group assignment take effect.


I think I can change the user's primary group in a running shell using the newgrp command - is there some alternative that would work for secondary groups?


Ideally, I'd want something that would take effect in each shell without being run manually in every one, but failing that, maybe some way of forcing Screen to execute the same command in each.



Answer



Horribly hacky, but you could use two layers of newgrp to achieve this for a particular group:


id -g

...will give you the current primary group ID. We'll call this orig_group for the purposes of this example. Then:


newgrp 

...will switch you to that group as the primary and add it to the list of groups returned by groups or id -G. Now, a further:


newgrp 

...will get you a shell in which you can see the new group and the primary is the original one.


This is horrible and will only get you one group added at a time, but it has helped me out a couple of times to get groups added without logging out/in my whole X session (e.g. to get fuse added as a group to a user so that sshfs will work).


Edit : This doesn't require you to type your password either, which su will.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...