If I add myself to a group, it applies only to newly launched processes. Actually it's more restricted than that; it seems to apply only to new logins. I'm not sure what the exact mechanism is, but that's not my question (though I'm curious about that too).

My question is this: Is it possible to update my group membership in the current shell process?

I suspect the answer is no.

An example (this is not a direct copy-and-paste):

$ groups ; groups kst
kst oldgroup1 oldgroup2
kst : kst oldgroup1 oldgroup2
$ sudo adduser kst newgroup
[sudo] password for kst:
Adding user `kst' to group `newgroup' ...
Adding user kst to group newgroup
$ groups ; groups kst
kst oldgroup1 oldgroup2
kst : kst oldgroup1 oldgroup2 newgroup

After the adduser, my account is a member of newgroup, but that membership is not reflected in the current shell process.

The obvious solution is to log out and log in again, but that's inconvenient.

marked as duplicate by Gilles, slm, jasonwryan, Joseph R., Thomas Nyman Oct 17 '13 at 3:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


It is not possible, from outside the process itself. See this SuperUser question for more discussion and an answer involving using a debugger to attach to the process and run setgid() from within it.

The reason it takes a new login to accomplish getting your new group memberships is that login (or sshd or whatever) runs as root, and must set process UID and GID for your shell process, which means it is already calling setuid and setgid.

Not the answer you're looking for? Browse other questions tagged or ask your own question.