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.
getent, id, passwd and chage for auditing.useradd (10 min)usermod (10 min)userdel (5 min)groupadd / groupmod / groupdel (10 min)passwd / chage (10 min)getent, id, lastlog (10 min)useradd – Create a New UserCreates a user with specified options.
sudo useradd -m -s /bin/bash newuser sudo useradd -m -s /bin/bash -G developers alice
bob with home directory and default shell.carol who belongs to the developers group.usermod – Modify an Existing UserChanges user attributes.
sudo usermod -aG sudo bob sudo usermod -L carol # lock account sudo usermod -U carol # unlock account
bob sudo privileges.carol's account and try to log in.userdel – Delete a UserRemoves user and optionally deletes home.
sudo userdel -r bob sudo userdel carol
carol without removing the home directory.carol no longer exists with id carol.groupadd, groupmod, groupdelCreate and alter groups.
sudo groupadd developers sudo groupmod -n devops developers sudo groupdel devops
admins.poweradmins.passwd – Set or Change PasswordPrompts for new password and updates /etc/shadow.
sudo passwd bob sudo passwd -l carol # lock password sudo passwd -u carol # unlock password
bob and confirm login works.bob's password and try to log in.chage – Account Aging & ExpiryConfigures password expiry and warnings.
sudo chage -l bob sudo chage -E 2025-12-31 bob sudo chage -M 90 bob
bob.ssh-keygen & authorized_keys – Key‑Based AuthenticationGenerates 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'
bob without a passphrase.bob to log in to localhost using the key.bob in /etc/ssh/sshd_config (optional).visudo – Configure Sudo PrivilegesEdits 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
bob passwordless sudo to restart apache2.admins full sudo rights.sudo -l -U bob.getent – Query System DatabasesRetrieves information from /etc/passwd, /etc/group, and NSS.
getent passwd bob getent group poweradmins getent shadow bob
bob using getent.poweradmins group.bob's encrypted password from shadow.id – Print User IdentityShows real, effective, and supplementary IDs.
id id bob id -Gn bob
id bob and interpret the output.bob belongs to.lastlog / faillog – Audit Login HistoryShows last login times and failed attempts.
lastlog -u bob faillog -u bob
bob last logged in.bob.usermod -aG – Add User to a GroupAppends group membership.
sudo usermod -aG poweradmins bob
bob to the poweradmins group.id bob that the group appears.chfn – Edit GECOS FieldsModifies the user’s full name, office, etc.
sudo chfn -f "Bob Builder" -o "42 Main St" -p "(555) 1234" bob
bob to “Bob Builder”.getent passwd bob.passwd -S – Show Password StatusReports on lock status, expiration, etc.
passwd -S bob
bob’s password is locked.passwd -S.useradd – Skeleton DirectoryCopies files from /etc/skel into the new user’s home.
sudo useradd -m -s /bin/bash -k /etc/skel newuser
dave that receives the skeleton files..bashrc exists in /home/dave.Students write a Bash script that takes a CSV file of usernames, groups, and password expiry dates, then:
~/.profile.They run the script for at least 3 test accounts and demonstrate the results with id, chage -l and lastlog.
Feel free to adapt the project or add optional commands (e.g., pam modules) if the audience is ready for more advanced user management.