To change a user's primary group in Linux, you can use the usermod command. Here’s how to do it:
Open the Terminal.
Use the
usermodCommand: The syntax for changing a primary group is as follows:sudo usermod -g new_primary_group username- Replace
new_primary_groupwith the name of the group you want to set as the new primary group. - Replace
usernamewith the name of the user whose primary group you want to change.
- Replace
Example: If you want to change the primary group of a user named
labexto a group calleddevelopers, you would run:sudo usermod -g developers labexVerify the Change: After changing the primary group, you can verify the change by using the
idcommand:id labexThis will show the user’s UID, primary GID, and all groups the user belongs to.
Note: You need to have superuser privileges to change a user's primary group, which is why sudo is used.
