In this article, we will see how to add user to Linux group.
Linux Group is collection of users. The main purpose of the Linux groups is to define a set of privileges like read, write, or execute permission for a given resource that can be shared among the users within the group.
How to add user to Linux group
Privileges required to add user to group are: A user account with sudo or root privileges.
Syntax to add user to group:
sudo adduser username new_group
1. Create a group called ‘sales’.
sudo addgroup sales
2. Add user ‘mike’ to group sales.
sudo adduser mike sales
3. Add user ‘david’ to multiple groups.
Syntax is:
usermod -a -G group1,group2,group3 exampleusername
sudo usermod -a -G sales,admin david
4. Verify the list of groups user added to.
groups david
5. Add multiple users to group.
sudo gpasswd -M r2schools,david,mike administrators
6. To get list of users added to a Group in Linux.
grep '^administrators:' /etc/group