What You'll Learn
Linux is a multi-user system. Every process runs as a specific user with specific permissions. This guide explains how users, groups, and elevated privileges (sudo) work.
Understanding Users
whoami # Show your current username
id # Show your user ID, group ID, and groups
cat /etc/passwd # List all users on the system
Every user has a unique numeric ID (UID). Root is always UID 0.
Creating Users
sudo adduser alice # Interactive way to create a user (recommended)
# or
sudo useradd -m -s /bin/bash alice # Create with home dir and bash shell
sudo passwd alice # Set the password
Removing Users
sudo userdel alice # Remove user (keeps home directory)
sudo userdel -r alice # Remove user AND their home directory
Understanding Groups
Groups let you manage permissions for multiple users at once.
groups # Show groups your current user belongs to
cat /etc/group # List all groups on the system
sudo groupadd developers # Create a new group
sudo usermod -aG developers alice # Add Alice to the 'developers' group
Common default groups:
sudoorwheel— Users who can run sudo commands.www-data— The web server user.dialout— Access to serial ports.
Sudo — Running Commands as Root
sudo command # Run a single command as root
sudo -i # Open an interactive root shell
sudo su - # Switch to the root user
The /etc/sudoers file controls who can use sudo. Edit it safely with:
sudo visudo # Always use visudo — never edit sudoers directly!
Passwordless Sudo (Use Carefully)
Add this line in visudo to allow a user sudo without a password:
alice ALL=(ALL) NOPASSWD: ALL
Su — Switch User
su - # Switch to root (need root password)
su - alice # Switch to user Alice (need Alice's password)
The - loads the target user's environment (home directory, shell settings).
Practice Exercise
whoami # Who am I?
groups # What groups am I in?
sudo adduser testuser # Create a new user (enter password)
sudo usermod -aG sudo testuser # Give them sudo access
su - testuser # Switch to the new user
whoami # Confirm you're now testuser
exit # Go back to your original user
Troubleshooting
- "user is not in the sudoers file": Log in as root and run
sudo usermod -aG sudo username. - Forgot your password? Boot into recovery mode to reset it.
What's Next?
You understand users — now learn how to manage running programs:
Process Management & Services →