Linux groups allow you to control who has access to certain files and processes. They can be used for a variety of reasons, such as letting different teams work together on the same project.
You can use the usermod command to add users to a group. However, this command requires sudo privileges because it modifies user accounts directly on the Linux system.
A user can only belong to one primary group at a time. Secondary or supplementary groups, on the other hand, let you share access to files and processes with others.
Creating user groups in linux is an important part of Linux administration. Whether you are a new user or an experienced Linux administrator, understanding how to create user groups can make your job easier.
First, you need to understand the different types of user groups in Linux. These groups have their own names, unique numerical identifiers (GIDs), and passwords.
The primary group is set to the logged-in user, which means that all files created by the user are automatically included in that group. Members of the primary group inherit all read, write, and execute permissions for that group.
In addition to the primary group, a user can also belong to zero or more supplementary groups. Supplementary groups are primarily used to manage individual files and software applications.
For example, a user in the careerkarma group can read and write files in the /home/careerkarma/tutorials folder. If the same user is in the QA group, they cannot access those files.
Moreover, you can specify which files and processes each user can access using the gpasswd tool. This can be useful for granting permissions to a group of users or setting a password for access to a group’s resources.
You can create a user with a specific initial login group by adding that group’s name or GID number to the useradd command. This option is useful for preventing users from accidentally creating secondary groups by naming the user’s group after a primary group.
After you have created a user, you can use the usermod command to modify that user’s password and membership in groups. You can also use this command to change the user’s primary and supplementary groups.
A user’s password is stored in a file named /etc/passwd. You can change the password using the usermod command or by editing the /etc/passwd file.
The group name is stored in a file called /etc/group. The group password is also stored in this file.
You can also use the useradd command to create a new group for an existing user, allowing them to access other files and process that are shared by multiple users. This allows for a more efficient way to assign user permissions on a Linux distribution.
You can use the usermod command to add an existing user account to a group by providing the username and groupname, which are separated by a space. Alternatively, you can add the user to multiple groups by providing all of the group names without any spaces between them.