Changing UNIX primary group

Inyeol Lee Inyeol_lee at
Wed Aug 13 17:52:40 CEST 2003

"Justin Johnson" <justinjohnson at> wrote in message news:<mailman.1060697959.27558.python-list at>...
> I have a unix id that has group1 for a primary group, and group2, group3,
> and group4 for supplementary groups.  I'd like to change my primary group
> before running certain commands.  So sometimes I might want group2 to be
> the primary group, and other times group3 or group4.
> I saw the posix module's setgid method, but it failed for me unless I was
> running as root.  Also it only accepts the gid, but I'd rather pass in
> the group name, or somehow lookup the gid based on the name.
> Does anyone know a way to do all of this?
> Thanks much.
> -Justin

These are not python solution;

1) make a setgid script and put your commands there, or
2) use shell commands;

   echo "command1; command2;" | newgrp group2


More information about the Python-list mailing list