When a member of multiple groups, how to set the default group for newly created files

grouppermissions

With umask, I can determine the permissions for newly created files. But if I am a member of multiple groups, how do I set the default group for newly created files?

This question seems relevant, but its answers relate how the system administrator can change the default group for a particular user. I am not system administrator, but just a mere user, and have no permission to do usermod -g even on myself. So how would I proceed to set the default group for newly created files?

Best Answer

To change your default group on the fly, use newgrp:

newgrp some_group

After running that command, you will be in a new shell with your group set to some_group and files that you create will be in group some_group. newgrp may or may not ask for a password depending on how permissions are set.

Related: To find out which groups you belong to, run groups.