Skip to main content

File Permissions

Linux file permissions are a core part of the operating system's security model. They determine who can read, write, or execute files and directories.


Understanding the Permission Format

Run ls -l in a terminal to see file permissions:

ls -l

Example:

-rwxr-xr-- 1 user group 1234 Jul 20 10:00 example.sh

Breakdown:

[File Type][User][Group][Others]
-rwx r-x r--

File Type

  • - : Regular file
  • d : Directory
  • l : Symbolic link

Permission Characters

  • r : Read
  • w : Write
  • x : Execute
  • - : No permission

Permission Categories

  1. User (Owner) – Permissions for the file's owner
  2. Group – Permissions for the group associated with the file
  3. Others – Permissions for everyone else

Each permission category contains 3 characters: r, w, and x.


Numeric (Octal) Representation

Each permission set maps to a number:

PermissionBinaryOctal
r1004
w0102
x0011

Examples:

SymbolicOctalMeaning
rwxr-xr-x755Owner: all, Group/Others: read + exec
rw-r--r--644Owner: read/write, others: read only
rwx------700Only owner can read/write/execute

Changing Permissions

chmod – Change file mode (permissions)

Symbolic Mode:

chmod u+x file     # Add execute to user
chmod g-w file # Remove write from group
chmod o=r file # Set read-only for others

Numeric Mode:

chmod 755 file     # Set rwxr-xr-x

chown – Change file owner

chown user:group file

chgrp – Change group ownership

chgrp groupname file

Directory Permissions

  • r : List contents (e.g., ls)
  • w : Create/delete files in the directory
  • x : Enter the directory (e.g., cd)

To access a directory, execute (x) permission is required.


Special Permissions

  1. SetUID (s) – Runs the file as the file owner (user)
  2. SetGID (s) – Runs the file as the group owner or preserves group in directories
  3. Sticky Bit (t) – In directories, only file owners can delete their own files
chmod u+s filename   # SetUID
chmod g+s filename # SetGID
chmod +t directory # Sticky bit

Quick Practice

touch testfile
chmod 755 testfile
ls -l testfile

Expected output:

-rwxr-xr-x 1 user group 0 Jul 20 10:00 testfile

Summary Table

SymbolMeaningWho
rReadView file
wWriteEdit file
xExecuteRun file
uUser (owner)File owner
gGroupGroup users
oOthersEveryone
aAllu + g + o

Calculate Permissions Easily

Use this online tool to calculate symbolic and numeric permissions:

👉 https://chmod-calculator.com/