Linux: Refresh user's group membership without logout/login

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Linux: Refresh user's group membership without logout/login

Post by ^rooker »

[PROBLEM]
If a system user is assigned newly to a group, this membership usually only takes effect after logging out and back in.

In some cases though, it's not that easy (or not possible) to simply logout and back in, so it would be great to apply that group membership immediately.


[SOLUTION]
You can join a group using the "newgrp" command (found that info in a debianhelp forum entry).

This only works on the fly, if the group has a group-password set, so the user can "join" it.
Even if you don't want to have group passwords (e.g. security reasons), I've decided in my case to temporarily add a password.

So here we go:
1) Assign a group-password to the group you want to join:

Code: Select all

gpasswd <groupname>
2) Join that group, using "newgrp":

Code: Select all

newgrp <groupname>
3) (optional) Verify that the group membership is now active:

Code: Select all

groups
That's it. :)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Re: Linux: Refresh user's group membership without logout/login

Post by ^rooker »

hmpf.
I've just discovered that "newgrp" opens another subshell - so if you've done the above, and wonder why you e.g. can't return into a backgrounded process...
well, type "exit" and you'll see that you've had another shell wrapped around.

Not tragic, but maybe good to know.
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply