How to Check Permissions of a File in Linux ?
Linux is one of the most popular operating systems powering VPS servers, web hosting platforms, and virtual machines across the world. At the core of Linux security lies its file permission system — rules that define who can read, modify, or execute a file. Knowing how to check permissions in Linux is essential for managing a VPS, setting up secure hosting environments, or working inside a virtual machine.
The Basics of File Permissions
Each file and directory in Linux has three types of permissions:
- Read (r) → view file contents or list a directory.
- Write (w) → modify or delete a file, add or remove files in a directory.
- Execute (x) → run a file (if it’s a program) or enter a directory.
And these permissions apply to three categories of users:
- Owner (user) → usually the creator of the file.
- Group → users belonging to the file’s group.
- Others → everyone else.
Checking Permissions with ls -l
The simplest way is to use the ls -l command:
Example output:
- -rw-r–r– → permissions
- user → owner
- group → group
- file.txt → filename
Here, -rw-r–r– means:
- Owner: read, write
- Group: read
- Others: read
Detailed Information with stat
For more details, use:
Example:
Now you see permissions in two forms: symbolic (-rw-r–r–) and numeric (0644).
Understanding Numeric Values
Permissions can be represented as numbers:
- Read = 4
- Write = 2
- Execute = 1
Adding them gives the permission value:
- rw- = 6
- r-x = 5
- rwx = 7
So 0644 = Owner: 6 (read/write), Group: 4 (read), Others: 4 (read).
Permissions for Directories
For directories, the rules are slightly different:
- r → list the names of files.
- w → create or delete files (if x is also set).
- x → enter the directory.
Example:
Here, the owner has full rights, the group can read/enter, and others have no access.
Special Permission Bits
Linux also supports advanced permissions:
- setuid (s) → run file with the owner’s privileges.
- setgid (s) → run file with group’s privileges.
- sticky bit (t) → in directories, only the file owner can delete their files (common in /tmp).
Example:
The t at the end means sticky bit.
Quick Reference Table
Symbolic | Numeric | Meaning (File) | Meaning (Directory) |
---|---|---|---|
— | 0 | No access | No access |
–x | 1 | Execute | Enter |
-w- | 2 | Write | Create/delete (with x) |
-wx | 3 | Write + Execute | Modify + enter |
r– | 4 | Read | List names (with x) |
r-x | 5 | Read + Execute | List + enter |
rw- | 6 | Read + Write | View + modify contents |
rwx | 7 | Full access | Full control |
Examples You’ll See Often
- -rw-r–r– (0644) → owner can read/write; others can only read.
- -rwxr-xr-x (0755) → owner can do everything; others can run but not modify.
- drwxrwxrwt (1777) → world-writable folder with sticky bit (like /tmp).
Conclusion
To check file permissions in Linux:
- Use ls -l for a quick look.
- Use stat for detailed output.
- Learn to read both symbolic (rwx) and numeric (755, 644) notations.
- Remember that directories follow the same rules but interpret x differently.
Once you understand these basics, permissions become a powerful and easy-to-read part of Linux security.