13.3 Diagnose and Correct File Permission Problems
Key Takeaways
- Diagnose with ls -l, ls -ld for directories, namei -l for path components, id/groups for the acting user, and optional getfacl when ACLs are in play.
- Correct mode bits with chmod (symbolic ugoa±rwx or octal) and ownership with chown/chgrp; fix directories and files deliberately—recursive -R only when intended.
- Permission failures are often on a parent directory (missing execute/search) even when the leaf file mode looks correct—namei reveals which path element blocks access.
- Separate DAC (ugo/rwx, owner, group) from SELinux denials; if modes look right but access still fails, check ausearch/journal and contexts in security objectives—still fix wrong chmod/chown first when ls shows the problem.
- Exam success is the required user can read/write/execute as specified after your diagnosis—not a blind chmod 777 on the whole tree.
13.3 Diagnose and Correct File Permission Problems
Quick Answer: Reproduce the failure as the right user, inspect with
ls -l,ls -ld, andnamei -l, fix withchmod/chown/chgrp, then re-test. Parent directories need execute (search) to reach files. Prefer least privilege overchmod -R 777.
Official skill
Under Create and configure file systems, Red Hat expects you to diagnose and correct file permission problems. Exam-style prompts:
- “User
alicecannot write to/data/shared/reports; fix permissions so her group can write.” - “The application user cannot traverse
/srv/app/config; correct directory permissions.” - “Only
bobshould own/home/bob/bin/tooland it must be executable by the owner.”
Related skills elsewhere: default umask, ACLs in depth, and SELinux contexts. This section focuses on diagnosis and DAC fixes (owner/group/mode) you apply under time pressure.
How Linux decides access (quick model)
For a process with a given UID/GIDs:
- If UID matches file owner, use owner rwx triad.
- Else if any process GID matches file group, use group triad.
- Else use other triad.
- ACLs (if present) can add per-user/per-group entries—check with
getfaclwhenls -lshows a+. - SELinux may still deny after DAC allows—different layer.
Directories interpret bits differently:
| Bit on directory | Meaning |
|---|---|
| r | List names (ls) |
| w | Create/delete entries (with x) |
| x | Search/traverse—enter path, access known child names |
A file mode rw-rw-rw- is useless if a parent is d--------- or lacks x for that user.
Diagnostic toolkit
ls -l and ls -ld
ls -l /data/shared/reports/file.txt
ls -ld /data /data/shared /data/shared/reports
ls -la /data/shared/reports
Sample line:
-rw-r-----. 1 root appgrp 4096 Aug 5 10:00 file.txt
drwxr-x---. 2 root appgrp 4096 Aug 5 10:00 reports
| Field | Meaning |
|---|---|
| First char | - file, d directory, l symlink |
rwx triads | owner, group, other |
. or + | SELinux mark (.) / ACL (+) on many RHEL listings |
| owner / group | chown / chgrp targets |
namei — the exam superpower for path issues
namei -l /data/shared/reports/file.txt
Walks each component with its owner/mode so you see which level denies traverse or read. Fix the component that fails—often /data/shared missing group x, not the leaf file.
Identity of the actor
id
id alice
groups alice
sudo -u alice id
You cannot fix “alice cannot write” while only testing as root. After changes:
sudo -u alice test -w /data/shared/reports && echo writable
sudo -u alice touch /data/shared/reports/t
sudo -u alice cat /data/shared/reports/file.txt
ACLs when you see +
getfacl /data/shared/reports
# setfacl -m u:alice:rwx /data/shared/reports # when task wants ACL semantics
If the task only mentions owner/group/mode, stick to chmod/chown. Use ACLs when group ownership alone cannot express the requirement.
Hidden culprits checklist
| Symptom | Likely cause |
|---|---|
Permission denied on open file | File mode or ownership |
Permission denied on path | Parent without x |
Can ls but not cd | Directory has r without x (or opposite confusion) |
| Can read but not write | Missing w on file or on directory for create |
| Root works, user fails | Expected DAC; fix mode/owner/group—not “bug” |
| Modes look open, still denied | SELinux, immutable attr (lsattr), wrong user/namespace |
lsattr /path/to/file # look for immutable i
sudo ausearch -m avc -ts recent # SELinux hints if DAC is fine
Correcting problems: chmod
Symbolic
chmod u+x script.sh
chmod g+w file.txt
chmod o-r file.txt
chmod u=rwx,g=rx,o= dir
chmod a+X dir # add x only if file is dir or already executable—useful carefully
Octal
chmod 755 /usr/local/bin/tool # rwxr-xr-x
chmod 640 /data/app.conf # rw-r-----
chmod 770 /data/shared # rwxrwx---
chmod 600 /home/bob/.ssh/id_rsa
| Octal digit | rwx |
|---|---|
| 7 | rwx |
| 6 | rw- |
| 5 | r-x |
| 4 | r-- |
| 0 | --- |
Recursion
chmod -R g+w /data/shared
Dangerous if it makes every file executable or world-writable. Prefer:
find /data/shared -type d -exec chmod 2775 {} \; # example policy
find /data/shared -type f -exec chmod 664 {} \;
Only when the task needs a whole tree policy.
Special bits (recognition)
| Bit | Octal | Effect |
|---|---|---|
| setuid | 4xxx | Run file as owner (binaries) |
| setgid | 2xxx | Run as group; on dirs, new files inherit group |
| sticky | 1xxx | On /tmp-like dirs, only owner deletes own files |
chmod 2775 /data/shared # setgid directory for group collaboration
chmod 1777 /data/tmp
Shared project directories often need setgid + group write + group execute so new files stay in appgrp.
Correcting problems: chown and chgrp
sudo chown alice file.txt
sudo chown alice:appgrp file.txt
sudo chown -R alice:alice /home/alice/project
sudo chgrp appgrp /data/shared
sudo chgrp -R appgrp /data/shared
Ownership mistakes:
- Service runs as
nginxbut files ownedroot:rootmode600→ web cannot read. - User’s home owned by root after botched copy → login quirks; restore
chown -R user:user.
You generally need root for chown to another user.
Worked diagnosis scenarios
Scenario A — Group write on shared directory
Problem: alice and bob in group staff cannot create files in /data/team.
id alice
ls -ld /data/team
# drwxr-xr-x root root → group has no write
sudo chgrp staff /data/team
sudo chmod 2775 /data/team
sudo -u alice touch /data/team/a
Scenario B — Parent path blocks access
Problem: ls -l /srv/app/config/app.conf as root shows -rw-r--r-- app app, but user app gets permission denied reading via the app path.
namei -l /srv/app/config/app.conf
# /srv may be drwx------ root root
sudo chmod 755 /srv
sudo chmod 755 /srv/app
sudo -u app cat /srv/app/config/app.conf
Fix search bits on parents; do not chmod 777 the config file only.
Scenario C — Script not executable
ls -l /usr/local/bin/backup.sh
# -rw-r--r--
sudo chmod 755 /usr/local/bin/backup.sh
# or chmod u+x
Scenario D — Wrong owner after unpack
sudo tar -C /opt -xf app.tar
ls -ld /opt/myapp
sudo chown -R myapp:myapp /opt/myapp
Scenario E — World-readable secret
Problem: Task says private key must not be group/other readable.
ls -l /home/bob/.ssh/id_rsa
sudo chmod 600 /home/bob/.ssh/id_rsa
sudo chown bob:bob /home/bob/.ssh/id_rsa
SSH itself rejects overly open keys—permissions are functional, not cosmetic.
Systematic exam procedure
- Identify user who must succeed (
id, task text). - Reproduce with
sudo -u user .... - Inspect leaf
ls -land pathnamei -l/ls -ldon each directory. - Decide: owner, group, mode, ACL, or other layer (SELinux/attr).
- Apply minimal
chown/chgrp/chmod(setgid share dirs when collaboration required). - Re-test as the user.
- Confirm you did not break other requirements (e.g., still not world-writable if forbidden).
chmod 777: when it is wrong
chmod -R 777 /var/www “fixes” many denials and fails real exams that expect controlled group access, breaks security assumptions, and may still fail under SELinux. Use 775/770 + correct group, or ACLs, matching the prompt.
Tie-in to file system creation
New ext4/XFS mounts are often owned root:root with 755. After mount, application tasks may require:
sudo mkdir -p /data/project
sudo chown alice:dev /data/project
sudo chmod 2775 /data/project
Creating the FS (13.1) and extending LVs (13.2) do not replace permission configuration for multi-user data directories.
Common traps
- Fixing only the file when a parent lacks
x. - Testing only as root — root bypasses DAC for most file modes.
- Wrong group membership — user not in the group you chmod’d for; use
usermod -aG/gpasswdwhen the task allows group changes (users/groups objectives). - Forgetting re-login after group add so new GID is active—or use
sg/newgrpin shell tests. chmodwithoutchownwhen ownership is the real bug.- Recursive 777 as a reflex.
- Ignoring
+ACL lines when basic ugo cannot explain access. - Treating SELinux denial as chmod problem forever—if modes are correct, pivot to contexts.
- Making directories 644 — directories normally need
xto be usable. - Breaking root-owned service files with careless
chown -Ron/etc.
Section checkpoint
You should reproduce access as the affected user, read modes and ownership with ls -l/ls -ld, walk components with namei -l, correct issues with targeted chmod and chown/chgrp (including setgid shared directories when appropriate), re-test without relying on root success alone, and escalate to ACL or SELinux tools only when DAC looks correct. That is the EX200 standard for diagnosing and correcting file permission problems on RHEL 10.
User alice gets “Permission denied” for /data/share/file.txt. ls -l on the file shows -rw-rw-r-- alice staff, and alice is in staff. Which diagnostic step best finds a parent directory blocking access?
Which command pair most appropriately gives group dev write and traverse on directory /srv/project while keeping other users out?
A script /opt/tools/run.sh shows -rw-r--r-- and will not execute when invoked as ./run.sh by its owner. What is the direct fix?
Why might chmod 666 on a file still leave a normal user unable to cat that file through a full path?