Linux File Permissions Basics
Learn how Linux file and directory permissions, ownership, groups, and numeric modes control access with ls, chmod, chown, and chgrp.
Why Linux permissions matter
Linux permissions are access rules applied whenever an account attempts an operation on a file or directory. They help protect private user data, shared project files, and critical system files from unintended reading, modification, deletion, or execution.
Permissions work differently for regular files and directories. For a file, the rules mainly control reading its contents, changing its contents, or running it. For a directory, the rules control listing names, changing directory entries, and traversing paths.
Ownership and permission classes
Every file and directory has an owner user and an owning group. It also has permissions for three classes of account:
| Class | Symbol | Who it applies to | Permission triplet position |
|---|---|---|---|
| User or owner | u | The account that owns the file | First triplet |
| Group | g | Members of the file's owning group, when the owner class does not apply | Second triplet |
| Others or world | o | Everyone else | Third triplet |
The account that owns a file is not automatically the same as every account in its owning group. User accounts can belong to groups, and a group can be assigned to files so that several collaborators receive a common access policy.
Linux evaluates the applicable class in order of identity: owner permissions apply when the accessing account owns the file; otherwise, group permissions apply when the account is an applicable member of the owning group; otherwise, the others permissions apply. The owner does not combine owner and group bits to get extra access.
Read, write, and execute permission bits
A permission bit is one read, write, or execute setting for one class. The symbols are r, w, and x.
| Permission | Symbol | Numeric value | Effect on a regular file | Effect on a directory |
|---|---|---|---|---|
| Read | r | 4 | Read the file's contents | List directory entries |
| Write | w | 2 | Change the file's contents | Create, remove, or rename entries, subject to other constraints |
| Execute | x | 1 | Run the file as a program or script when it is otherwise valid to execute | Search or traverse the directory and access known paths inside it |
Directory write permission controls changes to the directory's entries. Therefore, deleting or renaming a file is primarily an operation on its containing directory, not just on the file itself.
Directory execute permission is also called search permission. Execute without read can allow a user who knows a filename to traverse the directory and access that path when the target's permissions also allow it, while preventing a normal directory listing. Read without execute allows the directory's entries to be known or listed in some situations, but does not by itself allow traversal into the directory or access to its contents.
Examples of permission strings
Consider this regular file:
-rwxrw---- alice developers report.sh- The leading
-identifies a regular file. rwxgives owneraliceread, write, and execute access.rw-gives members ofdevelopersread and write access, but not execute access.---gives others no permissions.
Now consider this directory:
drwx------ alice alice privateThe leading d identifies a directory. The owner can list, enter, create, remove, and rename entries, subject to other system constraints. The group and others have no normal permission-based access.
This directory has search permission but no read permission:
d--x--x--x sharedUsers cannot list the directory's names, but a user who knows a permitted filename may be able to traverse the path. The target file's own permissions still determine whether it can be read or changed.
Viewing ownership and permissions
Use a long listing to inspect a file's mode, owner, group, size, and timestamp:
ls -l report.shA typical result may look like this:
-rwxrw---- 1 alice developers 1280 Jun 10 09:30 report.sh| Displayed segment | Example | Meaning |
|---|---|---|
| File type | - | Regular file; d indicates a directory |
| Owner permissions | rwx | The owner may read, write, and execute |
| Group permissions | rw- | Applicable group members may read and write |
| Other permissions | --- | Everyone else has no listed permissions |
| Owner name | alice | The associated user account |
| Group name | developers | The associated owning group |
The nine characters after the file-type character are read as three triplets: user, group, and others. A hyphen means that the corresponding permission is absent. Other leading characters can identify special file types, but the basic nine-position interpretation remains the starting point for ordinary files and directories.
To inspect the directory itself rather than its contents, use:
ls -ld directory_nameNumeric, or octal, permission modes
In an octal mode, read is worth 4, write is worth 2, and execute is worth 1. Add the enabled values for each class to produce one digit:
7= 4 + 2 + 1 = read, write, execute6= 4 + 2 = read, write5= 4 + 1 = read, execute4= read only0= no permissions
The three digits represent user, group, and others in that order. For example, 640 means owner read/write, group read, and no permissions for others.
| Mode | Symbolic form | Typical use | Security note |
|---|---|---|---|
600 | rw------- | Private configuration or credential file | Only the owner can read or modify it |
644 | rw-r--r-- | Regular file that others may read | Others cannot modify it |
700 | rwx------ | Private directory or owner-only executable | Only the owner has access through these bits |
755 | rwxr-xr-x | Publicly readable executable or traversable directory | Group and others cannot modify it |
770 | rwxrwx--- | Private shared directory for owner and group | Others have no access |
775 | rwxrwxr-x | Shared directory or program for owner and group | Others can read and traverse, but not modify |
777 | rwxrwxrwx | Rarely justified special case | Usually unsafe because anyone can modify or access it |
Do not use 777 as a default fix. Broad permissions can expose confidential data, allow unwanted changes, or let another user replace content. Identify whether the problem requires read, write, execute, ownership, group membership, or directory search permission, then change only that part.
Changing permissions with chmod
chmod changes a file or directory's permission mode. The owner can ordinarily change permissions on files they own. Changing permissions on files owned by another account may require authorized elevated privileges.
Symbolic modes
Symbolic mode uses a class, an operator, and permissions. The classes are u for user, g for group, o for others, and a for all classes. The operators are + to add, - to remove, and = to set exactly.
chmod u+x backup.sh
chmod g-w file
chmod o= filechmod u+x backup.shadds execute permission only for the owner and leaves existing group and other permissions unchanged.chmod g-w fileremoves group write permission.chmod o= fileremoves all permissions from others.
Multiple changes can be specified with commas, such as chmod u=rw,g=r,o= file.
Numeric modes
chmod 600 credentials.conf
chmod 640 shared-report.txt
chmod 755 tool.sh
chmod 755 project-directorychmod 600 credentials.conf allows the owner to read and modify the file while giving group and others no access. chmod 755 tool.sh gives the owner read, write, and execute access; group and others receive read and execute access but cannot modify the script.
Changing ownership with chown and chgrp
chown changes the owner and can optionally change the owning group:
chown user file
chown user:group file
sudo chown alice:developers report.txtThe last command makes alice the owner and developers the owning group. Changing ownership normally requires administrative privileges.
chgrp changes only the owning group:
chgrp projectteam notes.txt
chmod 660 notes.txtThis associates the file with projectteam, then gives the owner and applicable group members read/write access while denying access to others. The users still need to be members of the intended group.
Recursive ownership changes
The -R option applies an operation to a directory and its nested contents:
sudo chown -R user:group directoryUse recursive ownership changes only after verifying the exact target path and confirming that every nested item should receive the same ownership policy. Applying -R to the wrong path can change system files or unrelated user data. Recursive permission changes require even more care because files and directories often need different modes; a directory generally needs execute/search permission for traversal, while an ordinary data file usually should not be executable.
Safe permission-management workflow
- Inspect first. Run
ls -l fileorls -ld directory. Record the current owner, group, type, and permission triplets. - Identify the intended user. Decide whether access is for the owner, owning group, or others. Check group membership when shared access is expected.
- Identify the operation. Reading a file, editing its contents, listing a directory, traversing a directory, and deleting an entry can require different permissions.
- Apply the narrowest change. Prefer a focused command such as
chmod u+x script.shor a suitable group assignment over a broad mode such as777. - Be cautious with recursion. Use recursive operations only when one intentional policy applies to all nested contents.
- Verify afterward. Run the inspection command again and test the intended operation as the intended account when practical.
Troubleshooting permission errors
Permission denied when running a script
Check whether the file has the required execute bit, whether each parent directory has search permission, and whether the account matches the applicable owner, group, or others class.
ls -l script.sh
ls -ld /path /path/toIf the owner should run it, a narrow resolution may be:
chmod u+x script.shDo not grant execute access to everyone unless that is part of the intended policy.
A user can see a directory name but cannot list or enter it
Inspect the directory with ls -ld directory. Missing read permission prevents normal listing; missing execute/search permission prevents traversal. Add only the capability that is intended. Read and execute are separate directory permissions.
A user cannot modify a file even though the group has write permission
Confirm that the user is actually a member of the file's owning group. Also check the parent directory: creating, removing, and renaming entries depend primarily on directory permissions. Compare the requested operation with the relevant target—editing file contents differs from creating or deleting a directory entry.
Files became inaccessible after recursive chmod
A common cause is applying one mode to both files and directories. Directories generally need execute/search permission for traversal, while only programs and scripts that should run need file execute permission. Inspect representative files and directories separately, then restore modes according to their roles.
chown reports “operation not permitted”
The current account may lack administrative authority, or the filesystem may impose ownership restrictions. Check current ownership, account privileges, the target path, and the filesystem context. Do not change ownership merely to bypass an error without understanding the intended ownership model.
Exam-relevant points
- The nine basic permission positions are read as user, group, and others triplets.
- Numeric values are read
4, write2, and execute1; each class digit is their sum. - File read means reading contents; directory read means listing entries.
- File write changes contents; directory write changes entries such as creating, removing, or renaming them.
- Directory execute means search or traversal, and is required to reach known paths inside.
- Ownership determines which permission class is evaluated. The owner class does not combine with group permissions.
chmodchanges modes,chownchanges owner and optionally group, andchgrpchanges only group.- Recursive operations affect nested contents and should be used only with an intentional policy.
For a broader ownership workflow, see Manage File Ownership. You can also review the Linux File Structure to understand how paths and parent directories affect access.