Linux File Permissions Explained with Examples

Last updated on

To View Permissions

To list permission of each file in a directory, in this example /var:

ls -l /var


total 48
drwxr-xr-x   2 root root   4096  Feb  8  06:25 backups
drwxr-xr-x  13 root root   4096  Oct 22  00:29 cache
drwxrwxrwt   2 root root   4096  Aug 13  17:32 crash

To list file permissions for filename.txt:

ls -l filename.txt

To list directory permissions for /var:

ls -ld /var

Permission Groups

Each file and directory has three user based permission groups:

  • owner – The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
  • group – The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
  • all users – The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

Permission Types

Each file or directory has three basic permission types:

    • read – The Read permission refers to a user’s capability to read the contents of the file.
    • write – The Write permissions refer to a user’s capability to write or modify a file or directory.
    • execute – The Execute permission affects a user’s capability to execute a file or view the contents of a directory.

Numeric Meanings

Numeric Readable Explanation
0 No access.
1 –x Execute access.
2 -w- Write access.
3 -wx Write and execute access.
4 r– Read access.
5 r-x Read and execute access.
6 rw- Read and write access.
7 rwx Read, write and execute access.

Common File Permissions

Setting Numerical Owner Group Others
-rw------- 600 Read/Write
-rw-r----- 640 Read/Write Read
-rw-r--r-- 644 Read/Write Read Read
-rw-rw-r-- 664 Read/Write Read/Write Read
-rwx------ 700 Read/Write/Execute
-rwxr-xr-x 755 Read/Write/Execute Read/Execute Read/Execute
-rwx--x--x 711 Read/Write/Execute Execute Execute
-rw-rw-rw- 666 Read/Write Read/Write Read/Write
-rwxrwxrwx 777 Read/Write/Execute Read/Write/Execute Read/Write/Execute

Common Directory Permissions

Setting Numerical Owner Group Others
drwx------ (700) Read/Write/Execute
drwxr----- (750) Read/Write/Execute Read
drwxr-xr-x (755) Read/Write/Execute Read/Execute Read/Execute
drwxrwx--- (770) Read/Write/Execute Read/Write/Execute
drwxrwxr-x (775) Read/Write/Execute Read/Write/Execute Read/Execute

To Change Permissions

Single Files or Folders

To change permissions of file or directory to 644 for example:

sudo chmod 664 foo.txt

All Files

To change all files recursively to 640.

sudo find /path/to/directory/ -type f -exec chmod 640 {} \;

All Folders

To change all directories recursively to 750.

sudo find /path/to/directory/ -type d -exec chmod 750 {} \;

Let me know in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 5.00 (5 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces