hosting image
How to Add a User to a Group in Linux

How to Add a User to a Group in Linux

A group in Linux is a collection of users who share access to the same files and folders. By adding a user to a group, you may regulate their access to system resources. In this post, we will demonstrate how to add a user to a group in Linux.

Determine the Group Name in Step 1 Before adding a user to a group, you must establish the name of the group to which the user will be added. Using the “groups” command, you may obtain a complete list of all system groups. For instance:

$ groups

This will give a list of all groups to which the current user belongs. Use the “getent” command to obtain a list of every group on the system:

$ getent group

This outputs a list of all groups and their group IDs (GIDs) on the system.

Determine the Username in Step 2 Next, you must identify the username of the person you want to add to the group. Using the “getent” command, you may see a list of all system users.

$ getent passwd

This will provide a list of all system users and their respective user IDs (UIDs).

Step 3: Utilize the usermod command Once you have decided the name of the group and the user to add, you may add the user to the group using the usermod command. This command’s syntax is as follows:

$ sudo usermod -a -G group_name username

Replace “group name” with the name of the group to which you want to add the user and “username” with the user’s name. The “-a” option indicates that the user should be appended to the group, while the “-G” option gives the name of the group.

See also  Fedora Linux For Desktop & Server Computers

Verify that the user has been added to the group in Step 4. After adding the user to the group, you may use the “id” command to confirm that the user has been added. This command’s syntax is as follows:

$ id username

Replace “username” with the user’s name to be verified. This will reveal the user’s UID, GID, and a list of the groups they belong to.

Step 5: Sign out and sign in again For the changes to take effect, you must log out and log back in. After relogging in, the user should now have access to shared resources with the group to which they were joined.

Build your Linux VPS now for only $13

Conclusion In Linux, adding a user to a group is a straightforward procedure that may be completed in a few steps. By following this guidance, you can limit access to system resources and ensure that users have the necessary rights to complete their duties.

FAQ

You may need to add a user to a group in Linux to grant that user access to files, directories, or system resources that are only accessible to members of that group. For example, you may need to add a user to the "sudo" group to grant them administrative privileges.

5/5 - (2 votes)

3 Comments

  • Hello there, I found your web site via Google while looking for a related topic, your site came up, it looks great. I have bookmarked it in my google bookmarks.

  • Very interesting points you have remarked, thanks for posting. “The thing always happens that you really believe in and the belief in a thing makes it happen.” by Frank Lloyd Wright.

  • Very interesting information!Perfect just what I was searching for!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Setup Your Server