Reload a Linux user's group assignments without logging out
Solution 1:
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 <new_group_name>
...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 <orig_group_name>
...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).
Notes:
-
This doesn't require you to type your password either, which
su
will -
Each call to
newgrp
launches a new shell (as a child of the current shell) -
The current shell can be "replaced" with the
exec
commandexec newgrp <new_group_name>
-
Using
exec
will resolve the caching issue for the current branch of thepstree
I.e. if you are logged in to a window manager, every new terminal you launch will be a child of an earlier branch than the one "corrected" by this exercise and will therefore inherit the cached gid map.
Solution 2:
From inside a shell, you can issue the following command
su - $USER
id will now list the new group:
id