The Primary Group (the one labeled gid in the id command) primarily controls default ownership for everything you create.
Here is exactly what it controls:
1. Default File Ownership
Whenever you create a new file or directory, Linux needs to know which group should own it. It always picks your Primary Group.
- If your
gidis5000(labex), every file you create will automatically belong to thelabexgroup. - You can see this by typing
ls -l. You'll see your name (the owner) and your primary group (the group owner) listed.
2. Initial Permissions
Because your new files are owned by your primary group, the permissions set for the "group" (the middle rwx set) apply specifically to the members of that primary group.
- If you share a primary group with a coworker, they will immediately have "group" access to your new files by default.
3. Login and Execution
When you log in, the system starts your "session" under your Primary Group. While you can belong to many groups (secondary groups), your primary group is your "home" identity in the eyes of the system kernel.
Why is it different from secondary groups?
Think of it like this:
- Primary Group (
gid): Your "Department." It defines your identity. Everything you "build" belongs to this department by default. - Secondary Groups (
groups): Like "Club memberships." They give you extra permissions (like thesudogroup giving you admin powers), but they don't usually own the new files you create.
Pro Tip:
In modern Linux systems (like the one you are using in LabEx), it is standard practice to give every user their own private primary group named after themselves (User: labex, Primary Group: labex). This ensures that your files aren't accidentally shared with others unless you specifically move them to a different group!
Does that clarify how the gid functions compared to the other groups you saw?