PleinIQ
Menu
Language

Choose your language

This page is only in English for now. Choosing a language opens its home page.

Other languages

Your browser can translate any page into almost any language.

Other browsers: Open the browser menu and look for “Translate”.

Your resume, your downloads and lab commands are never translated.

Roadmaps / Linux / Lab 2

Lab 2 of 8 · Users, groups and permissions

Set up a team folder with the right permissions

Create users and a group, build a folder only that team can use, and give one user a single admin command through sudo.

Time
45–60 minutes
Cost
Free.

What you learn

Every file and process belongs to a user and a group, and permissions decide who can read, change or run it. Getting this right is most of day-to-day Linux security.

  • Creating users and groups, and expiring accounts
  • Read, write and execute permissions, in letters and numbers
  • A shared team folder with the setgid bit
  • Giving one admin command through sudo, safely

In the AI era: AI assistants often suggest `chmod 777` or blanket sudo rights to make an error go away. A sysadmin finds the smallest permission that works, and proves it with the system's own checks.

Get set up

Commands use Homebrew in the Terminal app. Already have a tool? Skip it.

  • Install
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Use the Terminal app. The command installs Homebrew, which the other macOS commands use.

Before you start

  • Finish lab 1.

  • Start your server and open your repository: run multipass start sysadmin-lab and multipass shell sysadmin-lab on your computer, then cd linux-admin-lab on the server.

Step by step

  1. 1 Create a team and two users

    alice joins the webteam group; bob does not.

    Run this on your lab server
    sudo groupadd webteam
    sudo useradd --create-home --shell /bin/bash --groups webteam alice
    sudo useradd --create-home --shell /bin/bash bob
    id alice
    id bob
    You should see:

    alice lists webteam among her groups; bob does not.

  2. 2 Build a shared folder

    2770 means the owner and the group can read, write and enter; everyone else gets nothing. The leading 2 (setgid) makes new files belong to the webteam group automatically.

    Run this on your lab server
    sudo mkdir -p /srv/webteam
    sudo chown root:webteam /srv/webteam
    sudo chmod 2770 /srv/webteam
    ls -ld /srv/webteam
    You should see:

    drwxrws--- with owner root and group webteam.

  3. 3 Prove who can use it

    sudo -u runs a command as another user, so you can test their access without their password.

    Run this on your lab server
    sudo -u alice touch /srv/webteam/plan.txt
    sudo ls -l /srv/webteam
    sudo -u bob ls /srv/webteam
    You should see:

    plan.txt belongs to group webteam, and bob gets Permission denied.

  4. 4 Give one admin command with sudo

    Never edit /etc/sudoers directly. Put a small rule in /etc/sudoers.d and let visudo check it: a broken sudoers file can lock everyone out of admin rights.

    Run this on your lab server
    echo 'alice ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx' | sudo tee /etc/sudoers.d/alice-nginx
    sudo chmod 440 /etc/sudoers.d/alice-nginx
    sudo visudo -cf /etc/sudoers.d/alice-nginx
    sudo -l -U alice
    You should see:

    parsed OK, and alice may run only /usr/bin/systemctl restart nginx as root.

  5. 5 Ask AI for a sudo rule, then check it

    Ask your AI assistant: "Write a sudoers rule that lets bob read the system journal and nothing else." Save its answer with nano /tmp/bob-rule, then check it before it goes live. Reject any rule that grants ALL, a shell or an editor: those give full root. Even journalctl can open a pager that starts a shell, so a safe rule pins --no-pager.

    Run this on your lab server
    sudo visudo -cf /tmp/bob-rule
    # only if the check passes and the rule is narrow:
    sudo install -m 440 /tmp/bob-rule /etc/sudoers.d/bob-journal
    sudo -l -U bob
    You should see:

    parsed OK, and bob's list shows one narrow command, such as /usr/bin/journalctl --no-pager.

  6. 6 Expire an account

    When someone leaves, expire their account instead of deleting it straight away, so their files stay for review.

    Run this on your lab server
    sudo usermod --expiredate 1 bob
    sudo chage -l bob | grep "Account expires"
    You should see:

    Account expires : Jan 02, 1970: the account can no longer be used.

  7. 7 Write your notes

    Create the file with nano notes/02-users.md.

    File: notes/02-users.md
    # Users, groups and permissions
    
    ## The team folder
    - Permissions on `/srv/webteam`: ...
    - What the setgid bit did: ...
    
    ## sudo rules
    - alice may run: ...
    - What the AI suggested for bob, and what I changed: ...
    
    ## Leavers
    - Why expire before deleting: ...
    
  8. 8 Commit and push

    Save your work to GitHub from the server.

    Run this on your lab server
    git add notes
    git commit -m "Add users, groups and sudo notes"
    git push

You are done when

  • /srv/webteam is drwxrws--- and only members of webteam can use it.

  • Every sudo rule passed visudo -c and grants single commands, never ALL.

  • notes/02-users.md is on GitHub.

Finished? Get your proof page

We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.

Join PleinIQ Updates

What are you interested in?

Read how we handle your information in our privacy notice.