woensdag 24 november 2010

Dynamically adding group membership in Linux

This is something I should have known years ago, but I didn't. So, here goes for those that don't know either and happen to stumble on my blog.

When installing some new software that only some users should have access to, a new group is created. The administrator then adds the user name of the users that are allowed to use the software to the entry for the group in /etc/groups.

If a user wants to use the new software immediately that won't work unfortunately. He has to log off and then on again before the system becomes aware of his new group membership.

For a console application however, there is a easy fix. Suppose you just installed rvm and created the new group rvm, let the user issue newgrp rvm and pronto: he will be able to use commands that rely on him being a member of rvm right away.

There are some side effects however. Not only will this group be added to the user's group set, it will become his primary group. Meaning a.o. that, by default, created files will receive the selected group as group id. If you want to avoid that, a user called `johndoe' should issue newgrp johndoe before invoking other commands. This will relegate rvm to secondary group again.