User Management – Linux Teaching Plan

This 2‑hour module teaches students how to create, modify, delete and audit users and groups on a Linux system. The plan assumes familiarity with the filesystem and basic shell usage.

Learning Objectives

Schedule & Topics

  1. Intro & UID/GID Overview (5 min)
  2. Adding Users – useradd (10 min)
  3. Modifying Accounts – usermod (10 min)
  4. Deleting Accounts – userdel (5 min)
  5. Managing Groups – groupadd / groupmod / groupdel (10 min)
  6. Password & Account Aging – passwd / chage (10 min)
  7. SSH Key‑Based Logins (10 min)
  8. Sudo Configuration (10 min)
  9. Auditing – getent, id, lastlog (10 min)
  10. Automation & Mini‑Project (15 min)
  11. Q&A & Wrap‑up (5 min)

Command Topics & Hands‑On Exercises

1. useradd – Create a New User

Creates a user with specified options.

sudo useradd -m -s /bin/bash newuser
sudo useradd -m -s /bin/bash -G developers alice

2. usermod – Modify an Existing User

Changes user attributes.

sudo usermod -aG sudo bob
sudo usermod -L carol           # lock account
sudo usermod -U carol           # unlock account

3. userdel – Delete a User

Removes user and optionally deletes home.

sudo userdel -r bob
sudo userdel carol

4. Group Management – groupadd, groupmod, groupdel

Create and alter groups.

sudo groupadd developers
sudo groupmod -n devops developers
sudo groupdel devops

5. passwd – Set or Change Password

Prompts for new password and updates /etc/shadow.

sudo passwd bob
sudo passwd -l carol          # lock password
sudo passwd -u carol          # unlock password

6. chage – Account Aging & Expiry

Configures password expiry and warnings.

sudo chage -l bob
sudo chage -E 2025-12-31 bob
sudo chage -M 90 bob

7. ssh-keygen & authorized_keys – Key‑Based Authentication

Generates a key pair and configures SSH access.

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
cat ~/.ssh/id_ed25519.pub | ssh bob@localhost 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'

8. visudo – Configure Sudo Privileges

Edits the /etc/sudoers file safely.

sudo visudo
# Add line
bob ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart apache2
# Or grant group sudo
%poweradmins ALL=(ALL) ALL

9. getent – Query System Databases

Retrieves information from /etc/passwd, /etc/group, and NSS.

getent passwd bob
getent group poweradmins
getent shadow bob

10. id – Print User Identity

Shows real, effective, and supplementary IDs.

id
id bob
id -Gn bob

11. lastlog / faillog – Audit Login History

Shows last login times and failed attempts.

lastlog -u bob
faillog -u bob

12. usermod -aG – Add User to a Group

Appends group membership.

sudo usermod -aG poweradmins bob

13. chfn – Edit GECOS Fields

Modifies the user’s full name, office, etc.

sudo chfn -f "Bob Builder" -o "42 Main St" -p "(555) 1234" bob

14. passwd -S – Show Password Status

Reports on lock status, expiration, etc.

passwd -S bob

15. useradd – Skeleton Directory

Copies files from /etc/skel into the new user’s home.

sudo useradd -m -s /bin/bash -k /etc/skel newuser

Mini‑Project: “Automated User Onboarding”

Students write a Bash script that takes a CSV file of usernames, groups, and password expiry dates, then:

  1. Creates the user with a home directory.
  2. Adds the user to the specified group.
  3. Sets an initial random password.
  4. Configures password expiry based on the CSV field.
  5. Writes a one‑time login message to ~/.profile.

They run the script for at least 3 test accounts and demonstrate the results with id, chage -l and lastlog.

Assessment

  1. Quick quiz (5 min) – 5 short answer questions.
  2. Hands‑on: Add a user, lock the account, unlock, delete, and verify each step (10 min).
  3. Script review: peer‑review each other’s onboarding scripts (10 min).

Resources

Feel free to adapt the project or add optional commands (e.g., pam modules) if the audience is ready for more advanced user management.