Fix Permission Denied When Opening a Linux File: A Beginner Guide
Before you begin
- Applies to:Ubuntu 26.04 LTS and Red Hat Enterprise Linux (RHEL) 10. The permission checks are the same on both.
- Where to start:Open Bash on the affected host as the user whose access failed.
- What you need:Have the exact path that returned Permission denied. For the optional practice exercise, use a folder under your home directory.
Guide tools
Troubleshooting Steps
Check the user and file permissions
Start hereReplace /srv/example/report.txt with the real path. The id command shows your user and groups. namei lists each part of the path and its permissions. A user needs search permission, shown as x, on each parent directory and read permission on the file itself. ACLs and security policy can also affect access.
What you should see Β· The output shows your user and groups, plus the owner and permissions for each part of the path.
If you see something else Β· Start with the first parent directory you cannot traverse. If all parents allow traversal, check read permission on the file. If both look correct, check the file ACL before changing permissions.
idls -l -- /srv/example/report.txtnamei -l -- /srv/example/report.txtPractice the narrow fix
Narrow the causeThis makes a fresh directory in your home folder and removes your own read permission from a practice file. The first cat should report Permission denied when run as a regular user. If it succeeds instead, the block restores owner read permission and exits with an error. Add owner read permission with chmod u+r and repeat. Run the block together so it stops if the practice directory or file cannot be created.
( lab=$(mktemp -d "$HOME/permissions-lab.XXXXXXXX") || exit 1 printf '%s\n' 'Practice only' > "$lab/report.txt" || exit 1 chmod u-r -- "$lab/report.txt" || exit 1 if cat -- "$lab/report.txt"; then chmod u+r -- "$lab/report.txt" || exit 1 printf 'Expected the read to fail. Practice folder: %s\n' "$lab" >&2 exit 1 fi chmod u+r -- "$lab/report.txt" || exit 1 cat -- "$lab/report.txt" || exit 1 printf 'Practice folder: %s\n' "$lab")Apply the lesson to the real path
VerifyAsk the owner to confirm the intended access. Correct only the relevant permission or group through the approved process, recording the old setting for rollback. Reopen the file as the intended user. If basic permissions are correct, check ACLs or ask the administrator to review security policy. Remove the practice file and empty folder with your file manager when finished.
Reference
Your feedback keeps these production procedures accurate and battle-tested.