Read a sample: 1. Build a Safe Permissions Lab
A permissions problem often begins with a simple question: “Why can’t I open this file?” The answer may involve the identity of the process making the request, the file’s owner and group, the permissions on a parent directory, or a separate access control mechanism.
The fastest way to learn those relationships is to work with files you can inspect, change, and rebuild. In this chapter, you will prepare a small Linux lab, establish a few habits that make experiments safer, and create a directory tree used for early practice.
You do not need to memorize every command on the first pass. The goal is to have a reliable place to experiment and a way to observe what each change does.
Use a Linux environment that does not contain important work. A virtual machine is a good choice because it gives you an isolated installation where you can create accounts and practice administrative tasks without deliberately changing your everyday system. A spare test machine can also work.
A container or a Linux environment integrated with another operating system can be useful for many exercises, but behavior may differ depending on its filesystem, configuration, and how it handles users or administrative privileges. If an exercise does not behave as expected, the environment itself may be part of the explanation. Chapter 13 returns to these boundaries.
For this chapter, you need:
- A Linux shell and a regular, non-root user account.
- A home directory where that account can create files.
- Basic tools such as pwd, ls, mkdir, touch, cat, and stat.
- Administrative access through sudo for later chapters, if your lab provides it.
You do not need administrative privileges to build the initial tree. In fact, creating it as your regular user is a useful first lesson: the identity that creates a file matters.
If your virtualization software supports snapshots, consider taking one after installing and updating the lab system but before making extensive changes. A snapshot can provide a broader recovery point than the reset procedure in this chapter, which only rebuilds the practice directory. Follow the documentation for your environment, and do not treat a snapshot as a substitute for backups of anything you need to keep.
Open a terminal and start by finding out where you are:
bash
pwd
The command prints the current working directory. Next, identify the account and groups associated with your current shell:
bash
whoami
id
A typical id result includes a username, a numeric user ID, a primary group, and any supplementary groups. Your names and numbers will almost certainly differ from those shown in examples elsewhere in the book.
Now inspect the home directory associated with your shell:
bash
printf '%s\n' "$HOME"
cd "$HOME"
pwd
The HOME environment variable normally contains the path to your home directory. Quoting "$HOME" keeps the shell from splitting the value if the path contains spaces. After changing directories, pwd confirms where you actually landed.
Throughout the book, paths beginning with "$HOME" refer to your own lab account. Run the examples from that account unless an exercise explicitly tells you to use another identity. Avoid running a whole shell as root for ordinary practice; doing so makes it harder to see which operations your regular account can perform.
Check whether sudo is available:
bash
command -v sudo
If the command prints a path, the program is installed. That alone does not prove your account is authorized to use it. If nothing is printed, or if your account cannot use sudo, you can still complete this chapter. Before later administrative exercises, consult the instructions for your lab environment or ask whoever manages it to provide suitable access.
Administrative privileges are powerful because they can allow a process to change files and account settings beyond the reach of an ordinary user. They are not a shortcut for understanding an access problem.
Before using sudo, make three checks:
1. Read the entire command. Know which program will run and which path it will affect.
2. Confirm the target. Inspect the directory or file before changing it, especially when using a recursive option.
3. Use privilege only for the operation that needs it. Return to unprivileged commands for inspection and verification whenever possible.
For example, prefixing a single command with sudo is easier to review than opening a root shell and continuing to work there. Even then, inspect the full command before pressing Enter. A mistyped path can affect a different location from the one you intended.
Do not add sudo merely because a command reports “Permission denied.” That message is evidence to investigate. The correct fix may be a group membership, a directory traversal permission, or a different target path—not broader privilege.
The following exercise creates a small workspace under your home directory. It contains a project area, a private area, and a shared area. These names describe the intended exercises; they do not by themselves guarantee privacy or sharing.
First, move to your home directory and check whether the proposed lab name is already in use:
bash
cd "$HOME"
ls -ld -- permissions-lab
If you see a message that the path cannot be accessed because it does not exist, you are ready to create it. If it already exists, inspect it and choose a different name rather than overwriting or removing something you may need. The examples below assume the name permissions-lab; if you choose another name, consistently…