User Accounts
Chapter 12 — Users, Permissions & Security
Linux was designed from the start as a multi-user system — multiple people can use the same machine, each with their own files, settings, and level of access. The permission system that makes this work also provides a strong security model: programs and users can only touch what they're explicitly allowed to. This chapter explains how users and groups work, how to read and change file permissions, and how to set up a basic firewall for a desktop machine.
1. Users and the Root Account
Every person who uses a Linux system has a user account with a unique username and a numeric UID (User ID). The system uses UIDs internally; usernames are just the human-readable label.
There is one special account: root (UID 0). Root has unrestricted access
to everything on the system — it can read, write, and delete any file, kill any process,
and change any setting. On desktop Linux, you are never logged in as root directly; instead
you use sudo to temporarily borrow root's powers for a single command.
/etc/passwd contains many
accounts with /usr/sbin/nologin as their shell — these are service accounts
(www-data for Apache, mysql for MySQL, etc.) that can't log in interactively. They exist
so that services run under a restricted identity, not as root. Filtering them out with
grep -v nologin shows only the real people accounts.
Managing users from the terminal
2. Groups
A group is a collection of users that share access to certain resources. Every file has both an owner (a user) and an owning group. Groups let you grant access to multiple users at once without making files world-readable.
When you install Linux and create your account, a group with the same name as your username is created automatically (your primary group). You also get added to several system groups that grant specific permissions:
- sudo (Ubuntu/Debian) / wheel (Fedora/Red Hat) —
allows use of
sudoto run admin commands - adm — read access to system log files in
/var/log - cdrom — access to optical disc drives
- plugdev — access to removable storage devices (USB sticks)
- lpadmin — manage printers
- docker — run Docker containers without sudo (added when you install Docker)
newgrp groupname in the terminal) before
the new group permissions apply. Running groups after usermod
won't show the new group until you log out.
3. Understanding File Permissions
Every file and directory in Linux has a set of permissions that controls who can read it,
write to it, and execute it. You can see these by running ls -l:
The first column is the permission string. Let's break it down:
What r, w, and x mean
- r (read, value 4) — on a file: can view the contents.
On a directory: can list what's inside (
ls). - w (write, value 2) — on a file: can modify or delete the contents. On a directory: can create, rename, or delete files inside it.
- x (execute, value 1) — on a file: can run it as a program or script.
On a directory: can enter it (
cd) and access its contents. - - (dash) — permission is not granted.
The first character — file type
- - — regular file
- d — directory
- l — symbolic link (a shortcut to another file or directory)
- b / c — block or character device (disks, terminals)
Numeric (octal) permissions
Permissions are often written as three digits — each digit is the sum of r(4), w(2), x(1) for owner, group, and others respectively:
- 644 —
rw-r--r--— standard file (owner writes, everyone reads) - 755 —
rwxr-xr-x— standard directory or executable (owner full, others read+execute) - 700 —
rwx------— private to owner only - 600 —
rw-------— private file (SSH keys use this) - 777 —
rwxrwxrwx— everyone can do anything (avoid this)
4. chmod — Changing Permissions
chmod (change mode) sets file and directory permissions. You can use numeric notation or symbolic notation.
400Read-only for owner (e.g., licence files)600Private file — owner read/write (SSH keys)644Normal file — owner writes, group/others read700Private directory or script755Standard directory or executable775Shared directory — owner and group writeuuser (owner)ggroupoothersaall (u + g + o)+add permission-remove permission=set exact permission5. chown — Changing Ownership
chown (change owner) changes who owns a file or directory. Only root (via sudo) can change file ownership.
sudo chown -R $USER:$USER path/
transfers ownership back to you. The $USER variable automatically expands
to your username.
6. sudo — A Bit More Detail
Chapter 11 introduced sudo. Here's a bit more of what it can do and how it's configured.
The sudoers file
sudo's configuration lives in /etc/sudoers and the directory
/etc/sudoers.d/. This controls who can use sudo and what commands they're
allowed to run. Always edit sudoers with visudo — it validates
the syntax before saving, preventing a broken sudoers file that would lock you out.
7. UFW — The Uncomplicated Firewall
Linux uses iptables (or the newer nftables) for packet filtering,
but configuring them directly is complex. UFW (Uncomplicated Firewall) is a
front-end that makes firewall management straightforward. It's pre-installed on Ubuntu and
available on most Debian-based distros.
Setting up UFW
Common UFW rules
After enabling with the defaults above, here's what the status looks like for a basic desktop that only allows SSH:
UFW on Fedora
Fedora uses firewalld instead of UFW. The graphical tool is firewall-config; the command-line tool is firewall-cmd. The concepts are the same — default zones, allowing services by name — but the syntax differs:
8. Good Security Habits for Desktop Linux
Most real-world attacks exploit known vulnerabilities that have already been patched.
Running sudo apt update && sudo apt upgrade weekly keeps security
patches applied. Don't ignore update notifications.
Your login password protects your sudo access. Use a password manager (Bitwarden, KeePassXC) to generate and store strong passwords. Avoid reusing passwords across accounts.
Never log in as root or stay in a root shell longer than necessary. The permission system only protects you if you're operating as a normal user. A mistake as root can destroy the system; as a normal user, the damage is limited to your own files.
Before running a sudo command you found online, understand what it does.
sudo rm -rf /, sudo chmod -R 777 /, and
curl url | sudo bash are examples that have caused real data loss for people
who ran them without checking.
Set your screen to lock automatically after a few minutes of inactivity (Settings → Privacy → Screen Lock on Ubuntu). Physical access to an unlocked machine bypasses all file permissions.
On laptops, LUKS encryption (set up during installation as covered in Chapter 5) protects all your data if the machine is stolen. Without it, anyone with physical access can read your files by booting from a live USB.
Stick to your distro's official repositories, Flatpak (Flathub), and well-known developer websites. Random scripts from forums, unverified PPAs, and pirated software are the most common vectors for malware on Linux.
SSH private keys should be 600 (owner read-only).
Configuration files with passwords should not be world-readable.
Run ls -la in sensitive directories occasionally to check nothing
has been accidentally made too permissive.
Chapter Summary
| Topic | Key commands and concepts |
|---|---|
| Users | sudo adduser name — create. sudo deluser name — delete. sudo passwd name — change password. id — see your own UID and groups. |
| Groups | sudo usermod -aG groupname user — add user to group (always use -a). groups — see your current groups. Takes effect at next login. |
| Permissions | Three sets (owner / group / others) × three bits (r=4, w=2, x=1). ls -l shows permissions. Common values: 644 (file), 755 (dir/exec), 600 (private), 700 (private dir). |
| chmod | chmod 644 file (numeric) or chmod u+x file (symbolic). chmod -R applies recursively to directories. |
| chown | sudo chown user:group file — change owner and group. sudo chown -R $USER:$USER path/ — reclaim ownership of a directory tree. |
| sudo | Temporary root access for one command. Configure with sudo visudo (never edit sudoers directly). sudo -l shows what you're permitted to run. |
| UFW firewall | sudo ufw default deny incoming → sudo ufw allow ssh → sudo ufw enable. Check rules with sudo ufw status verbose. Fedora uses firewalld instead. |