To add a user to a secondary group in Linux, you can use the usermod command with the -aG option. Here’s how to do it:
-
Open the Terminal.
-
Use the
usermodCommand:
The syntax for adding a user to a secondary group is as follows:sudo usermod -aG groupname username- Replace
groupnamewith the name of the secondary group you want to add the user to. - Replace
usernamewith the name of the user you want to add.
- Replace
-
Example:
If you want to add a user namedjokerto a secondary group calleddevelopers, you would run:sudo usermod -aG developers joker -
Verify the Change:
After adding the user to the secondary group, you can verify the change by using thegroupscommand:groups jokerThis will show all the groups that the user
jokerbelongs to, including the newly added secondary group.
Note: The -a option is important because it appends the user to the specified group without removing them from any other groups they are already a member of.
