To add users to a group in Linux, you can use the usermod command. Here’s how to do it:
-
Open a terminal.
-
Run the following command to add a user to a group. Replace
usernamewith the actual username andgroupnamewith the name of the group:sudo usermod -aG groupname usernameFor example, to add the user
johnto thesalesgroup, you would run:sudo usermod -aG sales john -
Verify the user has been added to the group by running:
groups usernameThis will display the groups that the user belongs to.
Important Notes:
- The
-aoption appends the user to the group without removing them from other groups. - You need administrative privileges to add users to a group.
- The user must already exist on the system.
