A teammate should be able to read a report without changing it. Linux file modes let the owner, the file's group and other users have different rights. First identify which relationship applies to the person accessing the file.
A mode is a set of permission bits, small on/off settings. For a regular file, r means read its content, w means modify its content, and x means execute it as a program, subject to other conditions. A dash means the corresponding right is absent. Directory permissions use the same letters with different effects.
Before you begin
- Recommended first
- Install Ubuntu LTS and open a terminal, Where practice is allowed, Users, groups, root, and sudo
- Estimated time
- 15 min reading, 15 min activity. Setup and optional practice may take longer.
- Where you work
- Use Bash in your owned Ubuntu practice environment as an ordinary user. The supplied text files use UTF-8, a text encoding; where shown, LC_ALL=C requests consistent text ordering. Work only under your own new ~/yanosec-lab directory, never a host share or personal/system file. Refuse an existing exercise destination rather than overwriting it. No account, paid platform, or remote target is required. Optional extensions take about 10–15 minutes and are not part of the time above. A virtual machine is optional. You can also finish the reasoning from the printed evidence.
- Without a lab
- The page supplies the files, source and text records needed for the activity. Without a shell, follow the numbered steps on paper, label each result as predicted, and use the separate evidence supplied by the question. Running commands can wait until your lab is available. Reading works without JavaScript. Answer checking needs JavaScript and a secure context, such as HTTPS; saving a correct result also needs usable browser storage. Missing tools, managed or mobile hosts, or a deferred guest setup never require buying a service. Keep owned lab files for review; do not use broad deletion.
After this lesson you can:
- Decode owner/group/others permissions in a regular-file mode.
- Predict access for a specified non-owner group member.
- Set and inspect a mode on a fresh owned text file without altering system files.
01Example
Start with an owned regular file named demo.txt. chmod 600 sets its owner to read/write while withholding ordinary group and other rights. The listing prefix below is a prediction; actual owner names, size and dates vary.
Command:
chmod 600 demo.txt
Numeric classes: owner | group | others
Mode 600: 6 | 0 | 0
Rights: rw- | --- | ---
Predicted regular-file prefix:
-rw-------
The first - marks the type; the next nine positions show rights.
Values within one class: read 4; write 2; execute 1.02Decode classes before adding values
The listing begins with a file-type character, such as - for a regular file, followed by three groups of permissions. Read those groups in order: owner, owning group, others. The owner is the user who owns the file; the owning group is its assigned group. Others covers users outside the first two classes.
Choose one class before deciding access. The owner uses the owner class even if also a group member. A non-owner in the owning group uses the group class; remaining users use others. Do not add rights from all three classes.
Numeric modes use octal, a base-eight numbering system whose digits are 0 through 7. For each permission digit, use read=4, write=2 and execute=1. Add only the present rights within each class. Thus 6 is read plus write, 4 is read alone, and 0 gives none. The worked 600 mode gives owner read/write and no group or other rights.
For the paper activity, decode 620: owner 6 means read/write; group 2 means write only; others 0 means none. A non-owner group member can modify content but does not gain read through those group bits. This separates choosing a class from assuming all writers can read.
Assume ordinary mode checks here: no access-control list, root override, other special privilege or blocked parent directory. An access-control list, abbreviated ACL, adds access rules beyond this simple display. In real troubleshooting, mode bits alone may be incomplete evidence.
For a directory, r allows listing names and x allows traversal, meaning reaching entries by name. With needed traversal, w allows changing directory entries. Removing a filename therefore depends mainly on the containing directory rather than on writing that file's content. Other restrictions can also apply.
Read each permission class independentlyModel. A teaching model drawn by hand. It shows the idea, not real tool output.
03Use a fresh owned workspace
The paths lesson introduced ~/yanosec-lab: ~ expands to your home directory. Before a file activity, return with cd ~/yanosec-lab. Use pwd to check your location and ls -a to inspect names. Continue only if this is your recognized owned lab. Then create the lesson's new child directory.
If mkdir reports that a destination already exists, preserve that work. Choose an unused name and use it consistently, or follow the paper route. Enter one command at a time and continue only after the preceding step succeeds. Record an unexpected result before doing anything else.
Unless the lesson says otherwise, leave the small activity folder for review and return with cd ~/yanosec-lab when finished. Closing the terminal does not delete files you saved. These activities need no sudo or system-file changes.
04Try an owned note mode
Only a new harmless regular file receives a mode change. chmod changes permission bits; it does not change file content or ownership. ls -l requests a longer listing that includes the displayed mode.
Follow the numbered steps only inside a new rights directory. The initial mode may vary. The worksheet supplies the expected before/after interpretation, so the paper route can trace a mode change without changing any real file. Keep that prediction separate from the check cards later on the page.
Read a mode one class at a time
First identify owner, owning group or others for the accessing user.
Then read that class only. Numeric modes use octal, base eight, with
digits 0 through 7. Within each digit, add the values of present rights.
Fresh paper activity: mode 620 gives group write without group read.
Explain why the owner still uses the owner class.
Assume ordinary mode checks only:
no ACL, root override, other privilege or ancestor access problem.
Class order: owner, group, others. Bits: read=4, write=2, execute=1.
Worked mode 600: owner rw; group none; others none.
Activity mode 640: owner rw; group r; others none.
Directory primer: r lists names; x traverses; w with x can modify entries.
File write and permission to delete its directory entry are distinct.
Activity fresh permission-note.txt: harmless practice note (newline).
Inspect before/after chmod 640; predict mode prefix -rw-r-----.
Question: a group member who is NOT the file owner accesses a regular
file with mode 640. Can that role write through the stated mode? yes/no
harmless practice note
- From the lab root, create mkdir rights and enter cd rights only after success. Write printf '%s\n' 'harmless practice note' > permission-note.txt in that fresh directory.
- Inspect ls -l permission-note.txt; record the initial mode and actual owner privately. Default creation permissions may vary with the creation mask, a setting that removes default rights, so do not expect a fixed initial mode.
- Run chmod 640 permission-note.txt. Inspect ls -l again. Expected mode prefix: -rw-r-----. No owner/group name or timestamp is fixed.
- Decode each class and explain why a non-owner group member lacks write under the stated ordinary-mode assumptions. You do not need another real user account or a failed write attempt to reason from the card.
- Restore this disposable file's private owner mode with chmod 600 permission-note.txt if desired, then return to the lab root and retain it. The paper route traces before/after modes without changing any file.
05Optional challenge
Allow about ten extra minutes. A regular file is readable, but its parent directory lacks traversal permission for the accessing user. Explain why the readable file bits alone do not establish that the user can reach it. Compare this with deleting an entry from a writable directory.
06Cards for the checks
The checks below use these cards. They are original fictional text, safe to read anywhere.
Regular-file listing for check 2: owner maya, owning group staffOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
-rw-r--r-- 1 maya staff 88 notes.txt
-rw-rw---- 1 maya staff 41 shared.txt
-rwx------ 1 maya staff 120 run.sh
-r--r--rw- 1 maya staff 12 odd.txt
07Fresh cases for the checks
Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.
Permissions card A: convert a regular-file modeOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Mode prefix: -r--rw---x
The first character describes the regular-file type.
Read the remaining positions in owner, owning-group, others order.
Permissions card B: independent group-access listingsOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Columns: mode | owner | owning group | filename
-r--r----- | Ivo | editors | brief.txt
-r-----rw- | Ivo | editors | decoy.txt
-r--rw---- | Ivo | editors | draft.txt
-rw---x--- | Ivo | editors | tool.txt
Actor: Nia belongs to editors and owns none of these regular files.
Assume accessible parent directories, ordinary mode checks, no ACLs,
no privilege overrides, and no other restriction on these content writes.
Permissions card C: a different actor relationshipOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Columns: mode | owner | owning group | filename
-r-xrw-rw- | Kai | reviewers | report.txt
Actor: Kai owns report.txt and also belongs to reviewers.
Questioned operation: writing the regular file's contents.
Assume accessible parent directories, ordinary mode checks, no ACLs,
no privilege overrides, and no other restriction on content writes.
Permissions card D: file rights and a containing directoryOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Columns: mode | owner | owning group | path
drwxr--r-x | Mara | readers | cabinet/
-rw-r--r-- | Mara | readers | cabinet/note.txt
Actor: Sol belongs to readers and owns neither entry.
Sol already knows the exact filename and wants to read its contents.
The path goes through cabinet. Earlier path components are accessible.
Assume ordinary mode checks, no ACLs or privilege overrides, and no other restriction.
Permissions card E: optional bounded repairOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Columns: mode | owner | owning group | filename
-r--rw---- | Ivo | editors | revision.txt
Intended change: let owner Ivo write the file contents as well as read them.
Keep every current group and others permission exactly as shown.
Do not add execute for anyone. Change only the necessary owner permission bit.
This is a paper mode calculation; no real file change is requested.
08Explain an access decision
Optional self-check: explain one denied access decision in three sentences. State the actor's relationship to the file or directory, the one class that applies, and the permission needed for the operation.
Check your explanation: do not combine classes or fall back to others after a denial. For a path, distinguish directory traversal from reading file contents. Keep the ordinary-mode assumptions beside your conclusion; real access can also depend on additional access rules and privileges.
09Common mistakes
If you decode the first character as an owner permission, separate the file-type marker from the following three triplets before counting positions.
If actual access differs from a mode-only prediction, inspect identity class, ancestor traversal, ACLs and privileges. Do not broaden rights to 777 to force success.
If chmod affects the wrong path or requires sudo, stop and inspect pwd and ownership. Use only the fresh controlled note or the paper card; no recursive or system mode change is needed.
References
- Ubuntu 24.04 packaged manual: chmod(1)
Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.
- Ubuntu 24.04 packaged manual: ls(1)
Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.