Linux & CLIbeginner8 min read

Linux File Permissions

Master Linux file permissions. Understand rwx notation, octal modes, ownership, and special bits like setuid and sticky bit.

Understanding Permission Notation

Every file and directory in Linux has three permission groups:

  • Owner (u) — the user who owns the file
  • Group (g) — users in the file's group
  • Others (o) — everyone else

Each group has three permissions: - r (read) — view file contents or list directory - w (write) — modify file or create/delete files in directory - x (execute) — run file as program or enter directory

The permission string `-rwxr-xr--` means: owner can read/write/execute, group can read/execute, others can only read.

Octal (Numeric) Mode

Each permission has a numeric value: r=4, w=2, x=1. Add them per group:

  • `755` = rwxr-xr-x (owner full, others read/execute)
  • `644` = rw-r--r-- (owner read/write, others read-only)
  • `700` = rwx------ (owner only)
  • `600` = rw------- (private file, owner read/write)

Changing Permissions and Ownership

Use chmod and chown to manage access:

# Symbolic mode
chmod u+x script.sh        # Add execute for owner
chmod g-w config.yml       # Remove write for group
chmod o= secrets.env       # Remove all permissions for others

# Octal mode
chmod 755 deploy.sh        # rwxr-xr-x
chmod 600 id_rsa           # rw------- (SSH key)

# Change ownership
chown alice:devteam app/   # Set owner and group
chown -R www-data:www-data /var/www  # Recursive

Special Permission Bits

Three special bits modify standard permissions:

  • Setuid (4xxx) — file executes as its owner, not the caller. Used by `passwd` to write to /etc/shadow.
  • Setgid (2xxx) — file executes as its group; on directories, new files inherit the directory's group.
  • Sticky bit (1xxx) — on directories, only the file owner can delete their files. Used on /tmp.
# Set the sticky bit on a shared directory
chmod 1777 /tmp

# Set setgid on a team directory
chmod 2775 /srv/project

Related Tutorials