Every process and file on a Linux system belongs to a user, and users are organized into groups that grant shared access. Understanding this model—and the sudo command that lets ordinary users borrow administrator power safely—is the difference between guessing at server errors and actually fixing them.
Linux identifies each user by a numeric UID and a name. Two kinds matter:
There are also system users like www-data, mysql and nobody: they never log in, but services run under them so a hacked web server cannot read the database files. See who you are:
whoami # your username
id # your UID, primary group and all group memberships
# uid=1000(sam) gid=1000(sam) groups=1000(sam),27(sudo),998(docker)User accounts are recorded in /etc/passwd (world-readable, no passwords despite the name); password hashes live in root-only /etc/shadow.
A group is just a named list of users. Give a file the group developers with group read/write, and every member can collaborate on it without opening it to the whole machine. Common groups you will meet:
sudo (Debian/Ubuntu) or wheel (Fedora/RHEL) – members may use sudodocker – may control the Docker daemonwww-data – web server filesgroups # which groups am I in?
getent group sudo # who is in the sudo group?Logging in as root for everyday work is dangerous—one typo can be fatal, and there is no audit trail. Instead, sudo (superuser do) runs a single command as root, after confirming your own password:
sudo apt update # run one command as root
sudo systemctl restart nginx # manage services
sudo -i # full root shell (use sparingly)
sudo !! # rerun the previous command with sudoWhy sudo beats a root login:
/var/log/auth.log)./etc/sudoers file—edited only with visudo, which checks syntax before saving and prevents locking yourself out.If you see sam is not in the sudoers file, an administrator must add you: usermod -aG sudo sam.
These commands need root, so prefix them with sudo:
sudo adduser alice # create user + home directory (interactive)
sudo passwd alice # set or reset her password
sudo addgroup developers # create a group
sudo usermod -aG developers alice # add alice to the group
sudo deluser alice # remove the accountThe -aG pair matters: -a means append. Forgetting it (usermod -G) replaces all of the user’s supplementary groups with the list you gave—a classic way to accidentally remove someone from sudo. Group changes take effect at next login (or after newgrp developers).
su - alice # become alice (needs her password)
sudo su - www-data -s /bin/bash # become a service user for debugging
exit # return to your own shellThe - gives you the target user’s full login environment, which avoids subtle PATH bugs.
whoami
id
groups
sudo whoami # should print: root
getent group sudoIf sudo whoami prints root, you have administrator rights on this machine—use them deliberately.
id and groups show your memberships.sudo runs one command as root with logging; configure it via visudo only.usermod -aG group user adds group membership—never forget the -a.www-data isolate damage if a service is compromised.Next lesson: Searching: grep, find and wildcards — locate anything on your system in seconds.