Skip to main content

Creating Users and Groups from the Command Line

Hands-On Lab

 

Photo of Michael Christian

Michael Christian

Course Development Director in Content

Length

00:45:00

Difficulty

Beginner

In this hands-on lab, we will practice adding users and groups from the command line. Creating, managing, and removing users and groups is a fundamental skill in Linux system administration.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating Users and Groups from the Command Line

Introduction

In this hands-on lab, we will practice adding users and groups from the command line. Creating, managing, and removing users and groups is a fundamental skill in Linux system administration.

Connecting to the Lab

  1. Open your terminal application, and run the following command (remember to replace PUBLIC_IP with the public IP you were provided on the lab instructions page):
    ssh cloud_user@PUBLIC_IP
  2. Enter yes at the prompt.
  3. Enter your cloud_user password at the prompt.

Create the Required Users

  1. List the current working directory.
    pwd
  2. Copy your cloud_user password to your clipboard.
  3. Run the following command to create the required users:
    for i in jen william matt sam anne danny kate bruce; do sudo useradd -m $i; done
  4. Enter your cloud_user password at the prompt.
  5. View the recent additions to the /etc/passwd file.
    tail /etc/passwd
  6. Note the newly created users in the output.

Create the Required Groups

  1. Run the following commands:
    sudo groupadd management
    sudo groupadd sales
    sudo groupadd operations
  2. View the recent additions to the /etc/group file.
    tail /etc/group
  3. Note the newly created groups in the output.

Add Members to the Appropriate Groups

  1. Add jen to all groups.

    sudo usermod -a -G management jen
    sudo usermod -a -G sales jen
    sudo usermod -a -G operations jen
  2. Verify that the user jen has been added to all three groups.

    groups jen
  3. Add william to all groups.

    for i in management sales operations ; do sudo usermod -a -G $i william; done
  4. Verify that the user william has been added to all three groups.

    groups william
  5. Add the users matt, sam, anne, and danny to the sales group.

    for i in matt sam anne danny; do sudo usermod -a -G sales $i; done
  6. Verify that this was successful.

    groups matt
    groups sam
  7. Add the users kate and bruce to the operations group.

    sudo usermod -a -G operations kate
    sudo usermod -a -G operations bruce
  8. Verify that group membership for both managers has been configured correctly.

    id jen
    id william
  9. Verify that group membership has been configured correctly for all users.

    tail -n3 /etc/group

Conclusion

Congratulations, you've successfully completed this hands-on lab!