Practice privilege escalation the way it looks on a real host:
run targeted commands with sudo, enter a root login
shell, switch users with a full login environment, then verify
sudo access through group membership.
You are training a junior admin on switching users and using sudo correctly. The goal is to demonstrate safe escalation patterns: run a single privileged command, open a root login shell for multi-step work, create a temporary admin user, grant them sudo via the correct group, validate access, then clean everything up.
The difference between “I can run sudo” and “I understand privilege boundaries” shows up in the command choices you make under pressure.
sudo.sudo -i.sudo or wheel).
sudo <command>
versus opening a root shell.
sudo -i.
useradd and setting a
password with passwd.
sudo (Debian/Ubuntu) vs wheel
(RHEL family).
su - to load the
target user's login environment.
sudo whoami.
userdel -r.
sudo ls /root
Use sudo for one-off privileged commands. It
limits blast radius and keeps a clean audit trail.
[sudo] password for lab:
file1.txt backup.tar.gz
sudo -i
sudo -i simulates a root login shell. Use it when
you have several admin tasks to perform and want consistent
root environment behavior.
useradd tempsudo
Creating a temporary account is a safe way to validate group rules and sudo policy without touching production users.
passwd tempsudo
This makes the account usable for su - and for
interactive sudo prompts.
# Debian/Ubuntu:
usermod -aG sudo tempsudo
# RHEL family:
usermod -aG wheel tempsudo
Many systems delegate sudo authorization through a privileged group. The group name differs by distro family, so you need to recognize both patterns.
exit
Dropping back to an unprivileged context is part of clean operational discipline.
su - tempsudo
su - loads the target user’s login environment,
which matters when you are testing PATH, profiles, and
group membership behavior.
sudo whoami
This is the quick identity proof: if sudo is working, the
output should be root.
root
sudo userdel -r tempsudo
Always remove training accounts and test access once the verification is complete.
sudo <command>
: Runs a single command with elevated privileges.
sudo -i
: Starts a root login shell (root environment).
useradd <user>
: Creates a new user.
passwd <user>
: Sets or changes a user password.
usermod -aG sudo <user>
: Grants sudo on Debian/Ubuntu by adding to the sudo
group.
usermod -aG wheel <user>
: Grants sudo on RHEL family by adding to the wheel
group.
su - <user>
: Switches to another user and loads their login environment.
sudo whoami
: Prints the effective user when running under sudo.
userdel -r <user>
: Removes a user and their home directory.