Add New User and Group

LinuxLinuxBeginner
Practice Now

Introduction

The LabEx R&D Team has one server where each team member has an account for daily routine jobs. Today, we have two new employees joining us, and we need to create their accounts.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux/UserandGroupManagementGroup -.-> linux/useradd("User Adding") linux/UserandGroupManagementGroup -.-> linux/usermod("User Modifying") linux/UserandGroupManagementGroup -.-> linux/passwd("Password Changing") linux/UserandGroupManagementGroup -.-> linux/sudo("Privilege Granting") linux/UserandGroupManagementGroup -.-> linux/groups("Group Displaying") linux/UserandGroupManagementGroup -.-> linux/groupadd("Group Adding") linux/UserandGroupManagementGroup -.-> linux/id("User/Group ID Displaying") subgraph Lab Skills linux/useradd -.-> lab-17987{{"Add New User and Group"}} linux/usermod -.-> lab-17987{{"Add New User and Group"}} linux/passwd -.-> lab-17987{{"Add New User and Group"}} linux/sudo -.-> lab-17987{{"Add New User and Group"}} linux/groups -.-> lab-17987{{"Add New User and Group"}} linux/groupadd -.-> lab-17987{{"Add New User and Group"}} linux/id -.-> lab-17987{{"Add New User and Group"}} end

Add New Users and Groups

In this challenge, you need to add two new users and two new groups to the system. You can accomplish this either by creating users and groups separately or by using a single command that sets up everything at once.

Tasks

  1. Create new groups named dev and test.
  2. Add a new user account named jack with a home directory of /home/jack, primary group dev, and secondary group labex.
  3. Add a new user account named bob with a home directory of /home/bob, primary group test, and secondary group labex.

Requirements

  • Use the labex user, which has sudo privileges and belongs to the labex user group, to perform these tasks.
  • Ensure that the new groups dev and test are created before adding the users.
  • Ensure that the new users are created with their respective home directories and group memberships.
  • You can choose either of these approaches:
    • Create groups first, then create users, and finally add them to groups
    • Create users with their group memberships in a single command

Examples

After completing the tasks, you should be able to verify the results as follows:

  1. For user jack, the output should be similar to:
$ id jack
uid=5001(jack) gid=5003(dev) groups=5003(dev),5000(labex)
  1. For user bob, the output should be similar to:
$ id bob
uid=5002(bob) gid=5004(test) groups=5004(test),5000(labex)
โœจ Check Solution and Practice

Summary

In this challenge, you learned how to add new groups and users to your system. You practiced creating groups, creating user accounts with specific home directories and primary groups, and adding users to additional groups. These skills are essential for user management in Linux systems, particularly when onboarding new team members or managing access control.