Group Management
Group Management
Managing groups
It's more efficient to group user accounts with similar access requirements than to
manage permissions on a user-by-user basis. Therefore, sysadmins need to be
comfortable with the process of creating, modifying, and deleting groups.
1. Understand the /etc/group file
Similar to the /etc/passwd file above, the /etc/group file contains group account
information. This information can be essential for troubleshooting, security audits,
and ensuring users can access the resources they need.
Understand each field of the file to make life easier as a sysadmin.
The fields in the /etc/group file are:
groupname:password:GID:group members
Here is an example of the editors group with two members:
editors:x:2002:damon,tyler
2. Create, modify, and delete groups
Like the user account commands described above, the group management
commands are very intuitive and provide a lot of flexibility. There is an easy-to-
remember command for each function you might need to carry out for a group:
•groupadd
•groupmod
•groupdel
8. Add User to Group
To add a user to a group, we can use gpasswd -a:
$ id new_user
uid=2027(new_user) gid=2027(new_user) groups=2027(new_user)
$ sudo gpasswd -a new_user baeldung
Adding user new_user to group baeldung
$ id new_user
uid=2027(new_user) gid=2027(new_user)
groups=2027(new_user),1000(baeldung)
The command has appended the specified group to new_user‘s groups.
9. Remove User From Group
We can use gpasswd -d to remove a user from a group:
$ id new_user
uid=2027(new_user) gid=2027(new_user)
groups=2027(new_user),1000(baeldung)
$ sudo gpasswd -d new_user baeldung
Removing user new_user from group baeldung
$ id new_user
uid=2027(new_user) gid=2027(new_user)
groups=2027(new_user)
The command has removed new_user from the specified
group.
10. Create a New Group
We can use groupadd to create a new group:
$ sudo groupadd new_group
$ cat /etc/group | grep new_group
new_group:x:2028:
The command has created a new group, and its group ID is 2028.