Linux Foundations / Understand Identity and Access

Explain file and directory permissions

Lesson 18 of 37. Open to read. No account needed.

A readable file can still be unreachable through its path. The permission to read its contents is a different check from the permission to search each parent directory. Likewise, seeing a filename in a directory listing does not necessarily let you inspect that file's metadata or open it.

You will use one fresh owned note to separate those checks. You will record the actual starting modes, remove exactly one known owner permission, observe the result, and restore that same bit. The examples use ordinary mode bits under the checked nonprivileged guest account, with no ACLs, special bits or privilege override in the fixture.

1. Read the mode and select one access class

Complete Inspect users, groups and ownership first. Keep the distinction between the current process's effective identity, its group set, and the owner/group identifiers on a file.

A basic mode has three permission groups: owner, group and other. For the ordinary access model used here, choose the applicable class in order:

  1. If the effective user ID matches the object's owner ID, use the owner bits.
  2. Otherwise, if the object's group ID matches the process's effective primary or supplementary groups, use the group bits.
  3. Otherwise use the other bits.

After selecting a class, a denied permission does not fall through to a more generous later class. For example, an owner without file-read permission cannot borrow the file's group-read or other-read bit. The same class-selection rule is applied separately to each relevant object along the path.

r, w and x are read, write and execute/search bits. A dash means that bit is absent. The meanings depend on the object:

BitRegular fileDirectory
rRead file contents.Read directory entry names.
wChange file contents, subject to the operation's other requirements.Change entries, such as creating or removing a name; ordinary entry changes also require directory search permission.
xExecute the file as a program, subject to its format and other requirements.Search/traverse the directory to resolve a known child name, including entering it with cd.

A path lookup needs search permission on each directory it traverses. An absolute path starts at /; a relative path such as cabinet/note.txt starts at the current directory and does not recheck ancestors above that starting point. Listing names and resolving those names are separate operations. Removing a file name concerns the parent directory's permissions; a file's own write bit is not a general deletion guard. This lesson changes no names during its permission experiment.

Numeric and symbolic modes describe the same basic bits

Within each class, read contributes 4, write 2 and execute/search 1. Adding the present values gives one octal digit:

DigitBits
0---
4r--
5r-x
6rw-
7rwx

Three digits describe owner, group and other in that order. For example, 640 describes owner read/write, group read and no other bits. That is an illustration, not a mode to impose on your file. Additional leading special bits are outside this exercise.

A hypothetical regular file with basic mode 244 has owner write only and read permission for group and other. Its owner is still denied a read through the owner class. This explains why class selection is not a permission fallback.

chmod changes mode bits. We will use symbolic single-bit changes: u means owner, - removes a bit and + adds it. Thus u-x removes only owner execute/search, while u+x adds that same bit. Similarly u-r and u+r remove and add owner read. These forms leave group and other bits alone. We will not set a guessed numeric mode or change a global umask.

2. Create the owned fixture and record its actual baseline

Use the checked Ubuntu guest's ordinary Bash user. Run commands one line at a time and read the result before continuing. Unexpected results mean pause further experimentation and follow the bounded restoration instructions; never apply a broad permission change as a repair.

id -u
id -un
id
ps -p $ -o comm=
type cd pwd printf set mkdir stat chmod cat ls rm rmdir

Require the expected nonzero ordinary identity, unchanged current groups and Bash. cd, pwd, printf and set must be Bash builtins; the utilities must use their expected guest executables. Reconcile unexpected origins before proceeding. Only an understood color-only listing alias is permitted.

Use the taught read-only shell-option check:

set -o

Require errexit off for the deliberately denied operations. Preserve a different setting and reconcile the baseline rather than changing it here.

The exercise owns ~/linux-practice/explain-file-and-directory-permissions/. Inspect parents and the prospective directory without trailing slashes:

ls -ld ~
ls -ld ~/linux-practice
ls -ld ~/linux-practice/explain-file-and-directory-permissions

Require ordinary owned parent directories without links or an unrecognized identity. The exercise name must be absent for a fresh start; use the resume section if it already exists. After confirming absence:

mkdir ~/linux-practice/explain-file-and-directory-permissions
ls -ld ~/linux-practice/explain-file-and-directory-permissions

Require the expected ordinary directory and owner, then enter and verify:

cd ~/linux-practice/explain-file-and-directory-permissions
pwd
ls -a

Record this exact outer exercise path. Require only . and .. before creating the sole child:

mkdir cabinet
ls -ld -- cabinet
ls -a cabinet

Require an ordinary owned empty directory. The taught text creation command now creates the absent note:

printf '%s\n' 'Permission checks preserve this note.' > cabinet/note.txt

Inspect the entries and saved contents:

ls -ld -- . cabinet cabinet/note.txt
cat cabinet/note.txt

Require the expected owned directories, an owned regular single-link note, and the exact supplied sentence with its terminating newline.

Record enough to restore, not just enough to recognize

The earlier stat format now adds two mode fields: %a prints the numeric mode in octal, and %A prints the symbolic type-and-permission representation. The known %n, %u, %g and %h fields label path, numeric owner/group and link count. Single quotes keep the full format together for stat:

stat -c 'path=%n mode=%a (%A) uid=%u gid=%g links=%h' -- . cabinet cabinet/note.txt

Record every actual mode, owner and group beside its path. Do not assume 755, 644, a primary group, or any other fixed starting number. Require owner rwx on the exercise directory and cabinet, and owner read/write on the note. Other ordinary group/other bits can differ; retain their values.

The fixture must have no symbolic links, extended/default ACLs or special mode bits. Inspect GNU ls -ld's mode/access indicators as well as stat. Require the ordinary ten-character type/mode field: the expected d or - type followed by nine positions containing only the expected r, w, x or -. A + indicates an additional access-control method such as an ACL. Stop for any added ACL, context or unknown indicator, or an unfamiliar mode. Special-bit symbols such as s, S, t or T, or additional special bits in the numeric mode, are also outside this exercise. Do not remove those features or broaden permissions to force an unsuitable fixture through the task. Resolve the declared ordinary setup first.

The inverse changes are safe only because the relevant owner bits were present in the recorded baseline: after removing cabinet owner x, restore it with chmod u+x -- cabinet; after removing note owner r, restore it with chmod u+r -- cabinet/note.txt. Both exact restoration commands are known before any restriction. Compare complete modes afterward to catch an unrelated change; a successful chmod alone is not the acceptance check.

3. Predict names, path access and file contents separately

The read test starts at the verified outer exercise directory. Before removing any bit, establish the normal observations. For the directory-name listing, we use two explicit GNU ls display controls: --color=never disables color metadata work, and --indicator-style=none disables appended type indicators. The taught -a includes dot entries. This is a names-only listing, not a request for long per-entry metadata:

ls -a --color=never --indicator-style=none -- cabinet
cat cabinet/note.txt

Expect the known note name and the unchanged sentence. Check a genuine traversal separately. ./cabinet explicitly names this current-directory child rather than consulting a bare-name CDPATH search:

cd ./cabinet
pwd

Require the recorded outer path followed by /cabinet. Return to the outer exercise directory and verify it before any mode change:

cd ~/linux-practice/explain-file-and-directory-permissions
pwd

Require the exact recorded outer path. The cabinet itself remains accessible as a named entry from this outer directory even when its own search bit is removed. That is why we stay outside it for the change and restoration.

Remove exactly the recorded owner-search bit

Recheck cabinet ownership and the recorded owner x before the controlled restriction. Predict all three results: names-only listing, reading the known file, and entering the directory. Then remove just owner search:

chmod u-x -- cabinet
stat -c 'path=%n mode=%a (%A) uid=%u gid=%g links=%h' -- cabinet

Require only the cabinet owner x to have disappeared. Its owner read/write bits, all other mode bits and ownership must remain as recorded. If another field differs, pause the comparisons and follow the restoration boundary below.

Now inspect directory names:

ls -a --color=never --indicator-style=none -- cabinet

Owner read still allows this names-only listing, so the note name can remain visible. That does not supply search permission. The following known-file read is deliberately expected to fail:

cat cabinet/note.txt
printf 'Read status: %s\n' "$?"

Expect a permission diagnostic and nonzero read status. Inspect status immediately; another command would replace it. The note's own read bit was not changed, but resolving its name inside cabinet needs the missing parent search permission. The diagnostic wording/language can vary.

Now try the explicit child traversal, also deliberately expected to fail:

cd ./cabinet
printf 'Traversal status: %s\n' "$?"
pwd

Expect a nonzero traversal status and pwd still equal to the recorded outer exercise path. If traversal unexpectedly succeeds, stop further tests: return using the explicit cd ~/linux-practice/explain-file-and-directory-permissions path, verify the recorded outer location, then restore the known removed bit before investigating the unexpected context. Do not issue a relative restore from an unverified location.

Restore before starting independent work

From the verified outer path and only for this known owned cabinet:

chmod u+x -- cabinet
stat -c 'path=%n mode=%a (%A) uid=%u gid=%g links=%h' -- . cabinet cabinet/note.txt
cat cabinet/note.txt

Require every recorded mode and ownership field to match the original baseline, and the exact note contents to be readable again. Recheck the names-only listing and explicit traversal, returning to the verified outer path afterward. Restoration is part of the task, not optional cleanup. If you cannot identify the location/target or verify the recorded baseline, stop without changing an unknown path and use the resume guidance.

The access class is selected once in owner, matching group, then other order with no fallback after denial. In the owned cabinet/note.txt path, removing cabinet owner-search blocks access before the still-readable file is reached; the relative lookup starts at the current directory and each directory it traverses needs search permission.

Read the green class arrows as ordered choices for each object. The blue path lookup starts at the current directory and stops at cabinet; the dashed note is unchanged but unreached. Directory search and file read are separate checks. The paired commands remove and restore that one recorded bit from the outer exercise directory, with no guessed numeric baseline.

Diagnose the object and operation before repairing

ObservationDistinction to inspectBounded next step
A filename is visible but its contents cannot be read.Directory-name reading differs from searching its entries and reading the file.Compare every parent-search requirement with the final file-read bit.
Group/other bits appear permissive but the owner is denied.Owner class was selected first; there is no fallback.Inspect the selected owner bit rather than adding unrelated group/other access.
A long listing shows errors after search is removed.Metadata lookups need more than reading entry names.Use the taught names-only observation; do not infer that it grants file access.
The ordinary test unexpectedly succeeds.The execution context or fixture may not match the bounded mode-only setup.Restore the known removed bit from the verified outer path, then investigate identity, extra access controls and actual mode evidence.
Adding a bit did not restore the original state.Another mode, path or ownership value may have changed.Compare the complete recorded baseline before continuing; do not use a blanket mode.

Independent task: repair the permission that the operation needs

Begin only after the guided baseline, contents and outer location are fully restored. Choose the minimum owner-bit repair for each supplied scenario:

  1. File-read scenario: all parent search permissions are as recorded, but the note's initially present owner r is missing. The ordinary owner wants to read the note. Which object and bit need repair?
  2. Directory-search scenario: the note's read bit is present, but cabinet's initially present owner x is missing. The owner wants to resolve and read the known note path. Which object and bit need repair?

Explain why adding permissions to group/other, changing the other object, or setting a guessed numeric mode is not the minimum repair. Both scenarios stay inside the known fixture; neither authorizes changing a system path.

Verify the first scenario on the existing owned note. Before changing it, recheck the current outer path, ordinary ownership, no extra access controls, and the original note owner r. You already know the exact recovery: chmod u+r -- cabinet/note.txt. Only then create the controlled condition:

chmod u-r -- cabinet/note.txt
stat -c 'path=%n mode=%a (%A) uid=%u gid=%g links=%h' -- cabinet cabinet/note.txt

Require only note owner read to differ from the baseline; cabinet remains fully restored. Predict and observe the deliberately denied read, then make the minimum repair you chose before opening the answer:

cat cabinet/note.txt
printf 'Read status: %s\n' "$?"

After your repair, inspect the complete original modes, ownership and text. Success: the denied read is explained by the selected file bit, the minimum repair restores the original readable note without changing other bits, and you distinguish that scenario from the earlier parent-search denial.

Graduated hints

  1. Identify the operation and object before choosing a letter. File read and directory search use different objects and different permission bits.
  2. The process owns both entries in this fixture, so the owner class applies. Group/other permissions are not an alternative after owner denial.
  3. Use the inverse of the one verified removal: owner read on the note for the first scenario, owner search on cabinet for the second. Compare the full recorded modes after repair rather than assuming a new mode value.

Answer and Reasoning

From the verified outer directory, after the independent note-read restriction, the minimum repair is:

chmod u+r -- cabinet/note.txt
stat -c 'path=%n mode=%a (%A) uid=%u gid=%g links=%h' -- . cabinet cabinet/note.txt
cat cabinet/note.txt

The note's owner read bit was the only removed requirement. Adding that bit restores the initial mode because it was proven present before removal. Require the original numeric/symbolic modes and owner/group IDs for all three entries, with the note still regular and single-link. Its complete contents must again be Permission checks preserve this note. followed by a newline.

For the second scenario, the minimum repair is the already demonstrated chmod u+x -- cabinet from the verified outer path. File readability alone cannot bypass the parent search check. Neither repair needs changed group or other bits, a different owner, a guessed full numeric mode or sudo.

Directory read explains the surviving name listing during the guided denial; directory search explains the failed read/traversal. Execute on a regular file instead concerns running it as a program, not directory traversal. The note is data; no execute permission or execution attempt is needed.

Cleanup only after exact restoration

Do not remove the fixture while its deliberate restrictions remain. First confirm the original mode, identity and content comparisons above. Reinspect the shared root, exercise and cabinet identities without trailing slashes:

ls -ld ~/linux-practice
ls -ld ~/linux-practice/explain-file-and-directory-permissions
ls -ld ~/linux-practice/explain-file-and-directory-permissions/cabinet

Require the known ordinary owned directories and no new ACL/special-bit/link condition. Enter and verify the outer path separately:

cd ~/linux-practice/explain-file-and-directory-permissions
pwd

Require the recorded outer exercise path. Inspect both inventories and the single named regular owned one-link note:

ls -a
ls -a cabinet
ls -ld -- cabinet/note.txt

Require only the known cabinet/note fixture and dot entries. Preserve unknown entries. The shown y/n responses assume English confirmations: establish the actual program's documented responses before removal and stop if unclear. Only after restoration and target checks:

rm -i -- cabinet/note.txt

Approve only that note. If declining, leave it and stop cleanup; with any multi-target interactive removal, every remaining prompt would also need its own refusal. Inspect ls -a cabinet and require only . and .. before:

rmdir -- cabinet
ls -a

Require the outer directory empty. Return to the shared root and verify it:

cd ~/linux-practice
pwd

Require the recorded shared-root path, then inspect the exercise entry:

ls -ld -- explain-file-and-directory-permissions

Only for that recognized owned empty directory:

rmdir -- explain-file-and-directory-permissions
ls -a

Retain the shared root and other lessons. No account, group, ACL, system mode or global umask was changed, so none needs restoring.

Resume with the restoration record

If interrupted during a restriction, first identify the ordinary guest and known outer exercise location. Use the explicit home-based path, then verify pwd and directory identities. Do not navigate by an assumed current location. Inspect the cabinet's mode from outside it before attempting note access.

If the record proves only cabinet owner search was removed, restore that one bit with chmod u+x -- cabinet, then compare complete modes. If it proves only note owner read was removed, with cabinet accessible, restore that bit with chmod u+r -- cabinet/note.txt. Both restorations depend on the original bit being present; do not apply them to an unknown pre-existing object.

If the original record is missing, another field differs or the target cannot be identified safely, preserve it and resolve the discrepancy before making further changes. Do not use a broad chmod, recursive repair or sudo to get past an unexplained state. After exact restoration, repeat read-only checks or use the named cleanup before deliberately rebuilding a fresh fixture.

Sources and other study views

The course uses the declared ordinary Ubuntu guest with GNU Coreutils 9.4. The upstream manual can describe newer releases; these bounded mode changes and observations do not claim coverage of every access-control mechanism. The path-resolution reference is an upstream Linux man-pages 6.19 companion, used for the lookup model rather than as a record of guest execution.

Revision reconstructs the permission decisions; Quick Reference retrieves the bounded commands after study.

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy