A group is a unit in Linux where you may simultaneously control rights for several users. Linux groups make it simple and quick to manage numerous user permissions. Learn how user groups function in Linux in this article. Including how to add users to a group or Linux useradd group. To reduce the need for multiple copies, simplifying updates and majorly creating shortcuts to files you need to Create Symbolic Link in Linux.

Administrators can restrict access to files, directories, and other system resources. Specifically by adding a user to a Linux group. Users can access, write, or execute certain files depending on their group membership. Which improves security and facilitates effective collaboration. When several users need access to a project folder jointly. When some users need administrator rights, proper group administration is especially helpful.

What is a Linux user group?

Different Linux users have various jobs or duties. Some users would need to be able to run programs. Whereas others might only be allowed access to certain files and directories.

You can build user categories with pre-defined rights using groups. To grant the necessary permissions to a user. You may just add them to a group rather than maintain permissions for each user account.

First Group

The logged-in user is designated as the primary group. The user’s files are automatically included in that group when they are created. One major group can have a user at a time. Any files that are created by the user are added to a primary group that is formed with the user’s name.

Additional Groups

Any number of secondary organizations, including none, are open to membership for users. To manage certain software programs and data, secondary groups are formed. The group’s read, write, and execute permissions are passed down to its members.

Creating a User Group

1. Enter the following information to create a new group:

sudo groupadd new_group

2. Substitute the desired name for your new group for new_group.

add new user group in linux

How to Join a Group as a User

Add a Current User to a Current Group

1. To include a user in a group, use the adduser command:

sudo adduser user_name new_group

adduser command to include user in group

2. To add a user, use the useradd command:

sudo useradd –G new_group user_name

3. The usermod command can also be used to include a user in a group:

sudo usermod –a –G group_name user_name

The -append and -group parameters of the usermod command are used to attach the user to a certain group. If -append is not used, the user might be removed from other groups.

At Once, You can Add a User to Several Groups

To add to several groups, use the usermod command:

sudo usermod –a –G new_group,new_group2,new_group3 user_name

Make a User and Include It in Group

1. This is helpful for instantly generating a new user for a certain software program. Put the following in:

sudo useradd –G new_group new_user

Next, give the new user a password:

sudo passwd new_user

Change the Primary Group of Users

The secondary groups a user is a member of can be managed by using any of the aforementioned instructions. A user’s primary group is typically the same as their username.

Enter the following command to modify a user’s primary group:

sudo usermod –g new_group user_name

The primary group is specified by the lowercase -g. (A secondary group is denoted by the uppercase -G.) The previous primary group for this user, user_name, will no longer be primary because a user can only have one primary group.

How to Exit a Group with a User

For managing groups, use the gpasswd tool. To expel a member of a group:

sudo gpasswd –d user_name new_group

Know How to Delete a Group

Use the following command to remove a group:

sudo groupdel new_group

use command to delete group in linux

Understand the Listing of Groups in Linux

1. By the etc/groups file you can view the list of groups on your System

sudo nano /etc/groups

2. This command will display the list of groups which the user belongs to.

groups

command to find groups of loggedin user

3. You can display the groups for a different user by specifying their username as shown above:

groups other_user

4. It is also possible to display the groups that a user belongs to using the id command:

id user_name

Final Thoughts on How to Add a User to a Group in Linux

It is simple to add a user to a Linux group, which gives the user more access privileges. It gives permissions inside the group’s boundaries. Linux users may efficiently manage group membership. Ensure appropriate collaboration, and resource sharing by understanding the methods needed.

As a result, being able to add users to Linux groups is a vital skill that improves user management. The access control in a Linux system. Learning group management will help you create a Linux system that is more secure. It is well-organized, whether it’s by granting more rights or creating resource-sharing features.