← Teacher guide

Accounts, groups and sudo

Each person gets an account and a private home folder. Groups give several accounts the same rights. Only users in the sudo group may use sudo, and the system logs every time they do.

System admin on a Raspberry Pi · People · about 40 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min

Before class

Try the boards yourself.

The one idea: accounts say who you are; groups and permissions say what you may do. This is authentication and authorisation (Security and privacy › Sign-in and permissions) on a real system.

Simplifications: the pretend Pi's pi account is not in the adm group, so reading /var/log/auth.log needs sudo (on a real Pi it does not). Passwords are always accepted. su alex starts a pretend session and exit returns.

On a real Pi: sudo adduser asks for a password and details; give each student their own account on the group's Pi so the log tells them apart. Never share the pi password.

Other options: useradd is the low-level version of adduser; visudo and /etc/sudoers.d/ give finer control over who may run what.

With internet: a school with many Pis would use one directory (for example LDAP or Microsoft Entra) rather than adding each account by hand.

Running the lesson

  1. Predict: wrong answers think 'logged in' means 'allowed everywhere'.
  2. Try: ask why a home folder is private by default.
  3. Worked example: stop at the -a question and ask what would happen to Alex's groups.
  4. Vary: after the log, ask what it would show if Alex had guessed passwords.
  5. Make: ask who should and should not get sudo.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

-a versus no -a on usermod. Show both on the board and run id after each.

When students get stuck

What you will seeA question to askThe fix
A student's usermod removed their other groups.Did you use -a?Use -aG, then check with id.
Permission denied reading the log.Did you use sudo?sudo cat /var/log/auth.log.

Answers to the checks

  1. Alex's folder: You create an account for Alex with sudo adduser alex. Can Alex open your home folder, /home/pi?
    No. Each home folder is drwx------: only its owner (and root) can open it. That is why a media server can't read films in a private home folder, a thing lesson 6 meets.
  2. Try: make an account: Make an account for alex with sudo adduser alex. Then look at its folder with ls -ld /home/alex.

    adduser makes the account, a group of the same name, and a private home folder.
  3. Groups and sudo: Which group lets a user run sudo?
    sudo
    Members of the sudo group may use sudo. That is the only difference between an administrator and a normal user here.
  4. Find the mistake: Sam gives Alex sudo. Click the line where it first goes wrong.
    line 2
    Line 2: -G on its own replaces all of Alex's groups. -aG adds one and keeps the rest: sudo usermod -aG sudo alex.
  5. The log: Where does the Pi record who used sudo?
    /var/log/auth.log, which only admins can read
    auth.log lists logins and sudo use, with the user and the time. Administrators read it to find out who did what.
  6. Add a group: Alex is in the group class. Add alex to sudo as well, keeping class.

    sudo usermod -aG sudo alex. The a matters: without it Alex would leave class.
  7. Read the log: Read the log that records logins and sudo use. Use sudo.

    sudo cat /var/log/auth.log. Without sudo it says Permission denied: pi is not in the adm group on this Pi.
  8. From Alex's side: Become alex with su alex. Try to read /home/pi/Documents/readme.txt. What happens?

    Permission denied: /home/pi is private. Accounts keep each other out until someone grants access.
  9. -aG: Which command adds alex to the group class and keeps alex's other groups?
    sudo usermod -aG class alex
    -a keeps the old groups, -G names the group to add.
  10. Why accounts: Why is it better to give people sudo through a group than to share the pi password?
    The log shows each person, and one can be removed
    Separate accounts mean the log says who did what, and removing one person doesn't mean changing the password for everyone.
  11. Review: exit: Review: you ssh to the Pi, then type exit. Which account are you now?
    Your laptop account
    exit ends the ssh session, and you are back on the laptop.
  12. a new administrator: Create an account for bob and give bob sudo.

    sudo adduser bob, then sudo usermod -aG sudo bob. Give sudo only to people who must use it.

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: change one thing › Add a group

Open task: any program that does what the step asks.

Vary: change one thing › Read the log

Open task: any program that does what the step asks.

Vary: change one thing › From Alex's side

Open task: any program that does what the step asks.

a new administrator

Open task: any program that does what the step asks.

Stretch and support

Stretch: Find out what the root account is and why Raspberry Pi OS leaves it without a password.

Support: A card: adduser makes, usermod -aG adds to a group, id shows.

Exit ticket

What is the difference between adduser and usermod -aG?

adduser makes the account and its home. usermod -aG adds an existing account to a group.

What each step is for

Where it leads

Links: Security and privacy › Sign-in and permissions; The command line › Who can read what; next: Services.