Linux on call · Chapter 16 of 30

Users and groups

By the end of this chapter you can make users and groups, put people in groups without taking them out of others, and read where Linux keeps it all. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Permissions and users
  • 4 tasks
  • Linux
  • In the all labs plan

The first 2 chapters of Linux on call are free. This one comes with the all labs plan.

Why you need this

Ravi has been doing operations from your account for a week. When something breaks, the logs say student did it, and nobody can tell who really did. His request is in request.txt: a login of his own, and a group for the kitchen display files, with him and Bunty in it. Bunty adds one line: do not take him out of tapri-interns.

So far you have changed files' owners and groups, but only to users and groups that already existed. Sharing your login is what Tapri does today, and it is the problem. Linux can make new accounts and groups, but the classic slip with groups quietly takes people out of the ones they had.

What you build: 4 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    Make the tapri-kitchen group

    The kitchen needs its own group, tapri-kitchen.

    1. Use sudo with groupadd to make the group tapri-kitchen.

    2. Run getent group tapri-kitchen to see it.

    To pass: the group tapri-kitchen exists on the system.

  2. Task 2

    Make Ravi's account, tapri-ravi, with a home folder and bash

    Ravi needs his own login: the user tapri-ravi.

    1. Use sudo with useradd to make the user tapri-ravi.

    2. In the same command, ask for a home folder and for /bin/bash as the login shell. Find the two options in the lesson.

    3. Run getent passwd tapri-ravi and list his home folder to check.

    To pass: the user tapri-ravi exists, his home folder exists and is owned by tapri-ravi, and his login shell is bash (/bin/bash).

  3. Task 3

    Put Ravi and Bunty in tapri-kitchen, and keep Bunty in tapri-interns

    Add Ravi and Bunty to the kitchen group, without taking away Bunty's other group.

    1. Use sudo with usermod to add tapri-ravi to the group tapri-kitchen as an extra group.

    2. Do the same for tapri-bunty. Append the group, so Bunty stays in tapri-interns.

    3. Run id tapri-bunty to see his groups.

    To pass: tapri-ravi is in tapri-kitchen, and tapri-bunty is in both tapri-kitchen and tapri-interns.

  4. Task 4 · interview question

    Interview: save Ravi's line from /etc/passwd in ravi.txt

    Interview question: what does one user's line in /etc/passwd look like?

    1. Do task 2 first, so Ravi's account exists.

    2. Use grep to find the line in /etc/passwd that starts with tapri-ravi and a colon.

    3. Save that line in ravi.txt, in the chapter folder.

    To pass: ravi.txt has Ravi's line from /etc/passwd, exactly as the file has it, and nothing else.

What you will learn

  • Users and groups: a number for each, a primary group, extra groups.
  • groupadd and useradd: make them, with the options a real login needs.
  • usermod -aG: add someone to a group, and why the a matters.
  • /etc/passwd and /etc/group: one line per user and per group.

More in Permissions and users

Build "Users and groups" yourself

Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Linux on call are free. This one comes with the all labs plan.