Skip to main content
On Linux, every process and file operation runs under a user account. Controlling who can log in, which files they can access, and what actions they can perform starts with correct user, group, and permission management. This guide explains how to read permission strings, manage ownership, apply file/directory permissions, and use special permission bits (SUID/SGID/sticky). Follow the examples and use ls -l frequently to verify changes.

Overview — the access metaphor

Think of a Linux system as a large office building:
  • Each file or directory is a room.
  • The owner is the person responsible for that room.
  • The group is a department that may share access.
  • Others are everyone else in the building. Permissions determine what each of these entities can do in a room: read, write, or enter/execute.

Reading permissions with ls -l

The ls -l command gives a long listing that reveals file type, permissions, ownership, size, and timestamps. What each field means:
  • First field: file type and permission bits
    • First character: file type (d = directory, - = regular file, l = symlink).
    • Next nine characters: three triplets (owner, group, others).
  • Second field: number of hard links.
  • Third and fourth fields: user owner and group owner.
  • Following fields: file size, modification time, and name.
Example:
  • The owner triplet (first 3 permission characters after the file type) applies to the user owner.
  • The group triplet applies to members of the file’s group.
  • The others triplet applies to everyone else.

Ownership basics

  • User owner: typically the account that created the file. They get the owner triplet.
  • Group owner: determines access for members of that group. Use groups to implement shared access across team members.
If a directory belongs to the group developers and group write permission is enabled, any member of developers can modify files in that directory (subject to directory entry permissions).

Basic permissions (r, w, x)

  • Read (r): For files, allows reading contents. For directories, allows listing contents.
  • Write (w): For files, allows modifying the file. For directories, allows creating or deleting entries.
  • Execute (x): For files, allows running the file (if executable). For directories, allows entering the directory (cd) and resolving inodes.
A dark-themed slide titled "Basic Permissions" showing a three-column table of Permission, Files, and Directories. It lists Read, Write, and Execute with their effects (e.g., read = can be opened/listed, write = can be edited/modified, execute = can be executed/entered).
Permission evaluation order (how the kernel checks access):
  1. Is the accessing user the file owner? If yes, use the owner triplet.
  2. Else, is the accessing user a member of the file’s group? If yes, use the group triplet.
  3. Else, use the others triplet.

Numeric (octal) and symbolic permission modes (chmod)

Use chmod to change permission bits. Octal mode:
  • Each permission triplet (owner/group/others) is a digit 0–7.
  • Each digit is a sum of read (4), write (2), execute (1).
Permission bit mapping: Examples:
Symbolic mode uses entities and operators:
  • Entities: u = user (owner), g = group, o = others, a = all
  • Operators: + = add, - = remove, = = set exactly
Example commands:

Special permissions: SUID, SGID, sticky bit

Special bits affect how executables run or how directories behave.
  • Set-user-ID (SUID): when set on an executable, processes launched run with the file owner’s effective user ID. Set with u+s.
  • Set-group-ID (SGID):
    • On executables: runs with the file’s group ID (g+s).
    • On directories: new files created inside inherit the directory’s group.
  • Sticky bit: on a directory, prevents users from deleting or renaming files they don’t own. Commonly used on /tmp (e.g., chmod 1777 /tmp).
Special bits are encoded as a leading octal digit:
  • 4 = setuid
  • 2 = setgid
  • 1 = sticky
Examples:

Changing ownership: chown and chgrp

  • chown changes user owner, optionally the group owner.
  • chgrp changes only the group owner.
  • Both support -R for recursive changes.
Examples:
Managing permissions without correct ownership can leave security gaps. Combine chmod with chown/chgrp to fully control access.

Demo: users, groups, ownership, and permissions

This example walks through creating users and a group, assigning group membership, creating a project directory, and applying ownership and permissions. Run as root (or use sudo where needed):
This sequence demonstrates:
  • Creating users and a group.
  • Granting supplementary group membership.
  • Creating files and directories.
  • Assigning ownership and permissions.
  • Using both symbolic and octal modes.
Use ls -l after each change to confirm results.
When designing access control, follow the principle of least privilege: grant only the minimum permissions required. Prefer using groups for shared access instead of broad “others” permissions.

Quick reference table

By mastering these commands and concepts, you’ll be able to control who can access files and directories on your Linux systems and apply secure, auditable permissions for both single-user and multi-user environments.

Watch Video