Modify File Permissions with chmod in Linux
Learn how Linux file permissions work and how to use chmod with numeric and symbolic notation to safely change access for owners, groups, and others.
Linux file permissions control whether users may read, modify, or execute a file or directory. The permissions are divided into three classes: the file owner, the owning group, and all other users.
The owner is the user account assigned to the file. The group is the file's assigned group class. Others means every user who is neither the owner nor a member of the owning group. The file owner and the root user can normally change a file's permission mode.
A permission mode is the set of access bits assigned to an object. The chmod command changes this mode without changing the file's owner or group membership.
Inspect Permissions with ls -l
Use ls -l to inspect a file's current permissions:
ls -l bobs_file.txt
A result might begin with:
-rw-r--r-- 1 bob developers 1200 Aug 17 10:30 bobs_file.txt
The first character identifies the object type. For a regular file, it is usually -. The next nine characters are three permission triplets:
- The first triplet,
rw-, belongs to the owner. - The second triplet,
r--, belongs to the owning group. - The third triplet,
r--, belongs to others.
Read the mode string from left to right as owner, group, others. You can also inspect the permissions before and after a change:
ls -l bobs_file.txt
chmod 764 bobs_file.txt
ls -l bobs_file.txt
Permission Bits: read, write, and execute
| Permission | Symbol | Meaning for a regular file | Meaning for a directory |
|---|---|---|---|
| Read | r | View the file's contents | List directory entries |
| Write | w | Modify the file's contents | Create, remove, or rename entries, subject to other permissions |
| Execute | x | Run the file as a program or script | Traverse or enter the directory and access items by name, subject to other permissions |
Permissions are evaluated separately for the owner, group, and others. For example, rw-r----- gives the owner read and write access, the group read access, and others no access.
The meaning of execute depends on the object type. Removing x from a script or program can prevent it from being run. On a directory, execute is primarily a traversal permission rather than a command-running permission.
chmod Command Overview
chmod is the Linux command for changing file or directory permission modes. Its basic pattern is:
chmod PERMISSIONS FILE
Replace PERMISSIONS with a numeric or symbolic permission specification. Replace FILE with a filename or path:
chmod 764 bobs_file.txt
For a path in another directory, provide the path after the permission specification:
chmod 644 documents/notes.txt
Numeric Permission Notation
Numeric notation, also called octal mode, represents read, write, and execute with values that are added together:
rread = 4wwrite = 2xexecute = 1
Each permission class receives one digit. The three digits are always ordered as owner, group, others. A digit is the sum of the enabled permission values. For example, 7 means 4 + 2 + 1, or read, write, and execute.
Complete numeric permission mapping
| Number | Permission letters | Meaning |
|---|---|---|
| 0 | --- | no permissions |
| 1 | --x | execute only |
| 2 | -w- | write only |
| 3 | -wx | write and execute |
| 4 | r-- | read only |
| 5 | r-x | read and execute |
| 6 | rw- | read and write |
| 7 | rwx | read, write, and execute |
Numeric mode examples
| Mode | Owner | Group | Others |
|---|---|---|---|
764 | rwx | rw- | r-- |
645 | rw- | r-- | r-x |
To assign owner read, write, and execute; group read and write; and others read, use:
chmod 764 bobs_file.txt
The digits represent owner 7, group 6, and others 4.
To assign owner read and write; group read; and others read and execute, use:
chmod 645 bobs_file.txt
The digits represent owner 6, group 4, and others 5.
Symbolic Permission Notation
Symbolic mode uses class letters, an operator, and permission letters. It is useful when you want to make a targeted change without replacing unrelated permissions.
| Component | Symbols | Purpose |
|---|---|---|
| Classes | u g o a | Choose owner, group, others, or all |
| Operators | + - = | Add, remove, or assign exactly |
| Permissions | r w x | Read, write, or execute |
umeans the owner, also called the user class.gmeans the owning group.omeans others.ameans all three classes: owner, group, and others.+adds a permission.-removes a permission.=assigns an exact permission set for the selected classes.
Adding and removing permissions
Add write access only for others with:
chmod o+w bobs_file.txt
This preserves the permissions already assigned to the owner and group. Add execute access for both the owner and others with:
chmod uo+x bobs_file.txt
Multiple class selectors can appear together. In uo+x, u and o are selected, and x is added to both.
Other examples include:
chmod g-w bobs_file.txt
chmod a+r bobs_file.txt
chmod u=rw,g=r,o= bobs_file.txt
g-wremoves write permission from the group.a+radds read permission for all classes.u=rw,g=r,o=gives the owner exactly read and write, the group exactly read, and others no permissions.
With =, permissions not listed for the selected class are removed. A symbolic command can therefore be exact for one class while leaving unselected classes unchanged.
Choosing Numeric or Symbolic chmod
- Use a numeric mode when you know the complete desired mode and want to assign it consistently.
- Use a symbolic mode for a targeted addition or removal, such as adding execute permission to the owner.
- Use symbolic mode when changing one class should not unintentionally replace permissions for the other classes.
For example, chmod 644 file.txt may look simple, but it overwrites all three class settings. If the goal is only to remove group write access, chmod g-w file.txt is more precise.
Permission Safety and Operational Cautions
- Grant write access to others only when every user outside the owner and group should be able to modify the object.
- Use the least-permissive mode that supports the intended access.
- Before removing
x, check whether users need to run the file or traverse the directory. chmodchanges permission bits only. It does not change ownership or group membership. Use the appropriate ownership commands when those properties must change.
For ownership concepts, see Manage File Ownership. To review how Linux identifies different object types, see Determine File Type.
Troubleshooting chmod
Operation is not permitted
If chmod reports that the operation is not permitted, the current user may not own the file and may not be root. Confirm the owner and group with:
ls -l bobs_file.txt
Switch to the owner account or use appropriately authorized administrative access.
The mode is different from what you expected
A numeric mode replaces the permissions for all three specified classes. Recalculate each digit, or use a symbolic expression for a single targeted adjustment.
A script no longer runs
Execute permission may have been removed for the user who needs to run the script. Inspect the mode and, if appropriate, add execute permission for the owner:
ls -l script.sh
chmod u+x script.sh
Other users cannot modify a shared file
Write permission may not be granted to the applicable class. Decide whether access belongs to the owning group or to others, then add write permission only to that class. Granting write access to others is broader and should be intentional.
A user still cannot access a file
The user may lack the required permission on a parent directory, may not belong to the intended group, or may be affected by another access-control mechanism. Check parent-directory permissions, ownership, group membership, and any system-specific access controls.
Exam-Relevant Summary
chmodchanges Linux permission modes.- The three classes are owner, group, and others.
r=4,w=2, andx=1.- Numeric digits are ordered owner, group, others.
+adds,-removes, and=assigns exact symbolic permissions.- Numeric modes replace the existing bits for the specified classes.
- Use
ls -lto verify the resulting permission triplets. chmoddoes not change ownership or group membership.