🌐 🇵🇱 Polski · 🇬🇧 EN
Now that we have users and passwords, it is time to create groups. Creating groups is similar to creating users. Let's learn the commands for creating and managing groups.
- id - Shows UID/GID for groups and specific users
- groupadd - Create a group
- groupmod - Modify group settings
- groupedel - Delete a group
Let's use the "groupadd" command to create a group.
groupadd command syntax: # groupadd [options] group
groupadd command options:
- -r - Create a system group
- -g GID - Set the GID number for the group
Creating a group :
# groupadd Sales
Just as users are contained in the /etc/passwd file, groups are contained in the /etc/group file.
GROUP FILE
Group file structure :
<group name>:<password placeholder>:<GID>:<members>
In this file, you can verify if new groups have been created.
# cat /etc/group | grep sales
sales:x:503:
Step 1 - Adding users to a group :
# usermod -G Sales user02
Step 2 - Verifying the addition :
# cat /etc/group | grep Sales
Sales:x:503:user02
Step 3 - Let's add another user to the Sales group :
# usermod -G Sales user03
Step 4 - and check what changes have occurred :
# cat /etc/group | grep Sales
Sales:x:503:user02,user03
Another way to verify is to use the "id" command.
id command syntax: # id [options] username
id command options:
- -G - Show GID
- -n - Show the name for the given ID
- -u - Show UID
Let's check which groups user02 belongs to.
# id -Gn user02
user02 Sales
If you run the "id" command without flags, you can see the UID and GID for the user.
# id user02
uid=501(user02) gid=501(user02) groups=500(user02) context=user_u:system_r:unconfined_t
Let's also check another user :
# id user03
uid=502(user03) gid=502(user03) groups=501(user03)
context=user_u:system_r:unconfined_t
If a group is no longer needed, it should be removed. Let's check the existing groups on the system :
# cat /etc/group | grep sales
sales:x:1005:
And we can easily delete the unnecessary group :
# groupdel sales
If we want to add a user to an additional group without replacing the ones they are already in, we use the command to add a user to groups by adding the "-a" flag, e.g.:
# usermod -a -G groupname username
If we want to add a user to an additional group without replacing the ones they are already in, we use the command to add a user to groups by adding the "-a" flag, e.g.:
# usermod -a -G groupname username
Comments