Changing UNIX primary group

Jeff Epler jepler at
Wed Aug 13 21:11:01 CEST 2003

On Wed, Aug 13, 2003 at 12:10:02PM -0600, Justin Johnson wrote:
> Thanks.  I was hoping for a python solution though.  :-(  Does anyone
> know of a way to do this in python?

Unix doesn't let you setgid() to groups in the supplemental group list
without the same permission needed to change to any group.

But depending what you need to do, you might be able to use set-group-id
directories.  For instance, if I am group g1 and have a group list [g1,
g2, g3], then I can read files readable by any of those groups, and
create files in directories writable by any of those groups.  But if you
make a directory d2 that is setgid g2 and d3 setgid g3, then when I
create a file in d2 it will belong to group g2.

Barring that, you could modify the setgid() call in the kernel, to permit
the change if the requested group is in the auxiliary group list.
It looks like something you could do in an afternoon if you have the
source for your kernel (bsd, linux, etc) and can program C.

"Justin Johnson" <justinjohnson at> wrote in message
news:<mailman.1060697959.27558.python-list at>...
> Also [setgid] only accepts the gid, but I'd rather pass in
> the group name, or somehow lookup the gid based on the name.

See grp.getgrnam().  Example:
        >>> grp.getgrnam("utmp")
        ('utmp', 'x', 22, [])


More information about the Python-list mailing list