User Group Management

ShellShellBeginner
Practice Now

Introduction

In this lab, you will learn how to manage user groups in Linux. You will learn how to create, delete, and manage user groups.

Achievements

  • groupadd - create a new group
  • groupdel - delete a group
  • groups - list groups a user is in

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) shell(("`Shell`")) -.-> shell/ControlFlowGroup(["`Control Flow`"]) shell(("`Shell`")) -.-> shell/SystemInteractionandConfigurationGroup(["`System Interaction and Configuration`"]) linux/BasicFileOperationsGroup -.-> linux/tail("`File End Display`") linux/UserandGroupManagementGroup -.-> linux/groups("`Group Displaying`") linux/UserandGroupManagementGroup -.-> linux/groupadd("`Group Adding`") linux/UserandGroupManagementGroup -.-> linux/groupdel("`Group Removing`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") shell/ControlFlowGroup -.-> shell/cond_expr("`Conditional Expressions`") shell/SystemInteractionandConfigurationGroup -.-> shell/globbing_expansion("`Globbing and Pathname Expansion`") subgraph Lab Skills linux/tail -.-> lab-50{{"`User Group Management`"}} linux/groups -.-> lab-50{{"`User Group Management`"}} linux/groupadd -.-> lab-50{{"`User Group Management`"}} linux/groupdel -.-> lab-50{{"`User Group Management`"}} linux/sudo -.-> lab-50{{"`User Group Management`"}} shell/cond_expr -.-> lab-50{{"`User Group Management`"}} shell/globbing_expansion -.-> lab-50{{"`User Group Management`"}} end

Show User Groups

In this step, we will learn how to show user groups. We will use the groups command to show the user groups.

The syntax is:

groups [options] username

List the groups for the root user:

groups root
root : root

List the groups for the current user:

groups

Sample output:

labex sudo ssl-cert public

Create a New Group

groupadd is used to create a new group. The group name must be unique. The group name must start with a letter and can contain letters, digits, underscores, and hyphens. The group name must be 32 characters or less.

The syntax is:

groupadd [options] groupname

Create a new group called devops:

sudo groupadd devops

Verify the group was created:

tail -n 1 /etc/group

Sample output:

devops:x:5003:

Delete User Group

groupdel is used to delete a group. The group must not have any members.

The syntax is:

groupdel [options] groupname

Delete the devops group:

sudo groupdel devops

Verify the group was deleted:

tail -n 5 /etc/group

You can see the devops group was deleted.

Summary

Congratulations! You have successfully completed the lab.

Linux user and group management is an important skill to have, especially if you are working in a Linux environment. You need learning how to create, delete, and manage users and groups.

Keep learning!

Other Shell Tutorials you may like