Linux Numeric Permissions
What Is Numeric Mode?
Linux allows you to change file and directory permissions using either symbolic mode (u+x, g-w) or numeric mode (755, 644).
Numeric mode uses numbers to represent permissions for the owner, group, and others. It is especially useful when you want to set all three permission categories in a single chmod command.
Permission Values
Each permission has a numeric value:
| Permission | Symbol | Value |
|---|---|---|
| Read | r | 4 |
| Write | w | 2 |
| Execute | x | 1 |
To calculate a permission value, add the numbers for the permissions you want.
For example:
- Read only:
4 - Write only:
2 - Execute only:
1 - Read + write:
4 + 2 = 6 - Read + execute:
4 + 1 = 5 - Write + execute:
2 + 1 = 3 - Read + write + execute:
4 + 2 + 1 = 7 - No permissions:
0
This gives us the following reference table:
| Numeric Value | Symbolic Permission | 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 |
Understanding the Three-Digit Format
The general syntax is:
chmod [owner][group][others] filenameEach digit represents the permissions for one category.
| Position | Category | Example |
|---|---|---|
| First digit | Owner | 7 |
| Second digit | Group | 5 |
| Third digit | Others | 5 |
For example, chmod 755 script.sh sets the permissions as follows:
- Owner:
7→ read, write, and execute (rwx) - Group:
5→ read and execute (r-x) - Others:
5→ read and execute (r-x)
The resulting permission string is:
-rwxr-xr-xThe leading - indicates that the entry is a regular file.
Practical Examples
Example 1: chmod 745 devops.txt
chmod 745 devops.txtBreak down each digit:
| Digit | Category | Calculation | Permission |
|---|---|---|---|
7 | Owner | 4 + 2 + 1 | rwx |
4 | Group | 4 | r-- |
5 | Others | 4 + 1 | r-x |
Result:
-rwxr--r-xThe owner can read, modify, and execute the file. Group members can read it, while others can read and execute it.
Note: The .txt extension does not make a file executable. Execute permission only allows execution when the file is a suitable executable or script.
Example 2: chmod 744 devops.txt
chmod 744 devops.txt| Digit | Category | Permission |
|---|---|---|
7 | Owner | rwx |
4 | Group | r-- |
4 | Others | r-- |
Result:
-rwxr--r--The owner has all three permissions, while the group and others have read permission only.
Example 3: chmod 644 file.txt
chmod 644 file.txtResult:
-rw-r--r--The owner can read and modify the file. Group members and others can read it but cannot modify it through their assigned permissions.
This is a common permission setting for regular files that need to be readable by other users.
Common Permission Combinations
| Command | Permission String | Typical Use |
|---|---|---|
chmod 400 file.pem | r-------- | Restrict a private key file to owner read access |
chmod 444 file.txt | r--r--r-- | Read-only access for all categories |
chmod 644 file.txt | rw-r--r-- | Regular files readable by others |
chmod 755 script.sh | rwxr-xr-x | Scripts or executables accessible to others |
chmod 700 private.sh | rwx------ | Owner-only access to a file |
chmod 777 file.txt | rwxrwxrwx | Read, write, and execute permissions for everyone |
Security tip: Avoid 777 unless there is a specific, justified need. It grants all three permission types to everyone, which can expose files to unwanted modification or execution.
For SSH private keys, 400 is one possible restrictive setting. The required permissions depend on the SSH client and its security checks.
Applying Numeric Permissions to Directories
Numeric mode also works with directories.
chmod 766 linuxIf linux is a directory, its permissions become:
drwxrw-rw-Here:
dindicates a directory.- Owner permissions
7(rwx) allow listing entries, creating or removing entries, and traversing the directory. - Group permissions
6(rw-) allow listing entries where permitted, but without execute permission, users generally cannot access entries by name. - Others have the same
rw-permissions as the group.
Important: Directory permissions behave differently from file permissions. Without execute (x) permission on a directory, read or write permission alone is generally insufficient to access entries inside it. The example above is therefore usually not a useful directory permission setting.
Verifying Permissions
After changing permissions, use ls -l to check the result.
chmod 755 script.sh
ls -l script.shExample output:
-rwxr-xr-x 1 ubuntu ubuntu 120 Oct 11 10:30 script.shThe permission string confirms that the owner has rwx, while the group and others have r-x.
Summary
- Numeric mode uses values from
0to7to represent permission combinations. - Read =
4, write =2, and execute =1. - A three-digit mode represents permissions for the owner, group, and others, in that order.
chmod 644 file.txtandchmod 755 script.share common examples for regular files and executable scripts.- Use
ls -lto verify permissions after making changes. - Choose permissions according to the access users actually need, especially when working with sensitive files or directories.
Remember: Symbolic mode is useful for changing specific permissions, while numeric mode is convenient for setting the complete permission set in one command.
Written By: Muskan Garg
How is this guide?
Last updated on
