Skip to content

Instantly share code, notes, and snippets.

@foyez
Created March 7, 2025 00:38
Show Gist options
  • Select an option

  • Save foyez/c6462ae93db594efc896be6648068e37 to your computer and use it in GitHub Desktop.

Select an option

Save foyez/c6462ae93db594efc896be6648068e37 to your computer and use it in GitHub Desktop.
Linux File Permissions

Linux File Permissions

Every file and directory in Linux has permissions assigned to three categories:

  1. User (Owner): A user is the owner of the file. By default, the person who created a file becomes its owner.
  2. Group: A user- group can contain multiple users. All users belonging to a group will have the same Linux group permissions access to the file.
  3. Others: Any other user who has access to a file.

Each category has three types of permissions:

  • r (Read) → Can view the file contents
  • w (Write) → Can modify the file
  • x (Execute) → Can run the file (if it's a script or program)

Trick to Remember Permission Numbers

Linux uses a 3-digit numeric system to represent permissions. The digits come from adding these values:

  • Read (r) = 4
  • Write (w) = 2
  • Execute (x) = 1

Each digit represents the sum of allowed permissions for User, Group, and Others.

Examples:

Permission Numeric Code Explanation
--- 0 No permissions (0)
--x 1 Execute only (1)
-w- 2 Write only (2)
-wx 3 Write + Execute (2+1)
r-- 4 Read only (4)
r-x 5 Read + Execute (4+1)
rw- 6 Read + Write (4+2)
rwx 7 Read + Write + Execute (4+2+1)

Example Breakdown: -rw-r--r--

-rw-r--r-- 1 foyez staff 1156 Feb 25 14:06 Makefile
  • - → This is a file (if it were a directory, it would be d)
  • rw- (User) → Read & Write (4+2 = 6)
  • r-- (Group) → Read only (4)
  • r-- (Others) → Read only (4)

How to Change Permissions?

Use the chmod command:

chmod 755 file.sh

This sets:

  • User: rwx (7)
  • Group: r-x (5)
  • Others: r-x (5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment