How To Change Permission In Linux

11 min read

Understanding how to change permission in Linux is a fundamental skill for anyone managing servers, developing software, or simply trying to secure their personal files. The Linux permission model acts as the first line of defense, controlling who can read, write, or execute specific files and directories. Without a solid grasp of chmod, chown, and the underlying numeric or symbolic modes, users often face frustrating "Permission denied" errors or, worse, inadvertently expose sensitive data to unauthorized users. This guide provides a comprehensive walkthrough of Linux file permissions, covering everything from basic syntax to advanced recursive changes and Access Control Lists But it adds up..

Understanding the Linux Permission Model

Before diving into commands, Make sure you visualize what you are modifying. It matters. Every file and directory in Linux has three distinct classes of ownership:

  1. User (u): The owner of the file (usually the creator).
  2. Group (g): A collection of users who share the same access rights to the file.
  3. Others (o): Everyone else on the system who is not the owner or in the group.

For each of these classes, there are three permission types:

  • Read (r): Value 4. Allows viewing file contents or listing directory contents.
  • Write (w): Value 2. Allows modifying file contents or creating/deleting files within a directory.
  • Execute (x): Value 1. Allows running a file as a program/script or entering a directory (cd).

When you run ls -l, the output displays a 10-character string (e.g., -rwxr-xr--). Even so, the first character indicates the file type (- for file, d for directory, l for symlink). The next nine characters represent the permissions for User, Group, and Others, in that order.

The chmod Command: Changing File Modes

The primary tool for modifying permissions is chmod (change mode). It operates in two distinct modes: Symbolic (text-based) and Numeric (octal-based). Both achieve the same result, but each has specific use cases where it shines Less friction, more output..

Using Symbolic Mode (Human-Readable)

Symbolic mode uses letters to represent who (u, g, o, a), what action (+, -, =), and which permission (r, w, x). This method is intuitive for granular adjustments Less friction, more output..

Syntax: chmod [who][operator][permission] filename

  • Who: u (user), g (group), o (others), a (all).
  • Operator: + (add), - (remove), = (set exactly).
  • Permission: r, w, x.

Practical Examples:

  • Add execute permission for the owner:
    chmod u+x script.sh
    
  • Remove write permission for group and others:
    chmod go-w document.txt
    
  • Set read-only for everyone (remove write/execute for all):
    chmod a-wx,a+r report.pdf
    
  • Copy user permissions to group (useful for collaboration):
    chmod g=u project_folder/
    

Symbolic mode is excellent when you want to tweak a specific bit without calculating the entire permission set from scratch Most people skip this — try not to..

Using Numeric (Octal) Mode (Efficient & Precise)

Numeric mode represents the permission triplet as a three-digit octal number. Each digit is the sum of Read (4), Write (2), and Execute (1) Simple, but easy to overlook..

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

Syntax: chmod [owner_digit][group_digit][others_digit] filename

Common Presets:

  • 755 (rwxr-xr-x): Standard for executables and directories. Owner has full control; group and others can read and enter/execute.
  • 644 (rw-r--r--): Standard for regular files. Owner can read/write; everyone else can only read.
  • 700 (rwx------): Private files/directories. Only the owner has access.
  • 775 (rwxrwxr-x): Collaborative directories. Owner and group have full control; others can read/execute.
  • 660 (rw-rw----): Shared group files. Owner and group can read/write; others have zero access.

Example: To secure a private SSH key, you would run:

chmod 600 ~/.ssh/id_rsa

This ensures only the user can read and write the key, satisfying SSH's strict security requirements.

The chown and chgrp Commands: Changing Ownership

Permissions are useless if the wrong user owns the file. Consider this: chown (change owner) and chgrp (change group) modify the metadata linking a file to a user or group. These commands require sudo (root) privileges.

Changing the User Owner

sudo chown newuser filename

Changing the Group Owner

sudo chgrp developers project/

Alternatively, chown can do both simultaneously:

sudo chown newuser:developers project/

Recursive Ownership Changes

When migrating a web application or restoring backups, you often need to apply ownership to an entire directory tree. Use the -R (recursive) flag:

sudo chown -R www-data:www-data /var/www/html

Pro Tip: Use the --reference=FILE flag to copy ownership from an existing file, avoiding typos in usernames:

sudo chown --reference=/etc/passwd /etc/shadow

Advanced Permission Concepts

Beyond the basic rwx triad, Linux features Special Bits that modify execution behavior or directory deletion rules. Which means these are represented by a fourth leading digit in octal mode (e. g., 4755) or specific letters in symbolic mode Easy to understand, harder to ignore. No workaround needed..

1. Setuid (Set User ID) - Value 4

When set on an executable file, the process runs with the privileges of the file owner (often root), not the user who launched it Less friction, more output..

  • Symbolic: chmod u+s file
  • Octal: chmod 4755 file
  • Visual: rwsr-xr-x (lowercase 's' implies execute is also set; uppercase 'S' means execute is not set).
  • Use Case: The passwd command allows regular users to modify /etc/shadow (owned by root) because the binary has the setuid bit.

2. Setgid (Set Group ID) - Value 2

  • On Files: Process runs with the file's group privileges.
  • On Directories (Crucial): Files created inside the directory inherit the directory's group ownership, not the creator's primary group. This is the standard way to manage shared project folders.
  • Symbolic: chmod g+s directory
  • Octal: chmod 2775 directory
  • Visual: drwxrwsr-x

3. Sticky

The Sticky Bit – Guarding Shared Directories

When a directory carries the sticky flag (octal value 1), its contents become resistant to accidental removal. Still, even if a user has write permission on a file inside that directory, they can only delete or rename it if they are the file’s owner or the directory’s owner. This nuance is essential for locations such as /tmp or collaborative work folders where many users share the same space.

# Give a shared folder the sticky attribute
chmod +t shared_folder        # symbolic form
chmod 1777 shared_folder      # numeric form (rwx for all, plus sticky)

In practice, the sticky bit turns a “anyone can write” directory into a “no one can erase another’s files” space. The kernel enforces this check during every unlink or rename operation, regardless of the file’s individual permissions Worth knowing..


When to Use Setuid and Setgid

Setuid (4) is typically attached to a binary that must perform a privileged operation on behalf of the caller. The classic example is passwd; it needs to modify /etc/shadow, a file owned by root. By setting the setuid bit, the program temporarily elevates its effective user ID to root while still preserving the caller’s environment.

chmod 4755 /usr/bin/passwd

Setgid (2) behaves similarly but for group identity. On a regular file, it forces any executed program to run with the file’s group ID. On a directory, it ensures that every new file or sub‑directory created inside inherits the directory’s group ownership instead of the creator’s primary group. This is the cornerstone of collaborative projects:

chmod 2775 /srv/www

Security note – Misuse of setuid/setgid can open privilege‑escalation paths. Only assign these bits to trusted, well‑audited binaries, and regularly review their presence on the system And it works..


Other Special Attributes

Beyond the three classic special bits, Linux offers additional file‑system attributes that modify behavior at a deeper level:

Attribute Effect Typical Use
Immutable (+i) Prevents any modification, deletion, or renaming of the file, even by root (unless the attribute is cleared). That said, Protecting critical configuration files. In practice,
Append‑only (+a) Allows writes only to the end of a file; existing data cannot be overwritten or truncated. Logging services that must retain a tamper‑evident record. And
No‑atime (+n) Stops updating the file’s access timestamp on reads, reducing disk I/O. High‑performance servers where every write operation counts.

These flags are set with chattr and are largely independent of the traditional rwx permissions, providing an extra layer of control for system administrators.


Symbolic vs. Numeric Modes

Both chmod syntaxes—numeric (e., 644) and symbolic (e.Consider this: g. g.

# Remove write permission for group while preserving everything else
chmod g-w file.txt

# Add execute permission for owner and group, but not for others
chmod u+x,g+x file.sh

# Strip all permissions and then grant read‑only access to everyone
chmod 000 file.txt && chmod a+r file.txt

The numeric representation is concise and less error‑prone for common scenarios (e.g., 755 for a directory that should be traversable and executable by all, yet writable

only by the owner), while symbolic mode excels at surgical changes—toggling a single bit without needing to calculate or recall the full octal value.

A particularly powerful symbolic operator is the capital X (conditional execute). Unlike lowercase x, which applies execute permissions indiscriminately, X adds execute permission only if the target is a directory or already has at least one execute bit set. This makes recursive operations safe for mixed trees of files and directories:

Counterintuitive, but true The details matter here..

# Make a tree traversable without turning every text file into an executable
chmod -R u+rwX,g+rX,o+rX /var/www/html

Here, directories receive rwx (traversal), scripts and binaries keep their x bit, but regular data files remain rw-—exactly what you want for a web root Not complicated — just consistent..


Access Control Lists (ACLs): Beyond the Standard Trio

When the traditional User/Group/Other model proves too coarse—say, a developer needs write access to a directory owned by www-data without joining that group—POSIX ACLs provide per-user and per-group granularity.

# Grant user 'alice' read/write/execute on the project dir
setfacl -m u:alice:rwx /srv/project

# Grant group 'designers' read-only access
setfacl -m g:designers:rx /srv/project/assets

# View the resulting ACL (note the '+' suffix on the mode string)
getfacl /srv/project
# file: srv/project
# owner: root
# group: www-data
# user::rwx
# user:alice:rwx
# group::r-x
# group:designers:r-x
# mask::rwx
# other::r-x

The mask entry limits the maximum effective permissions any ACL entry can grant, acting as a safety ceiling. Default ACLs (setfacl -d) propagate rules to newly created children, enabling true “set-and-forget” collaborative directories without relying on the setgid bit alone Worth knowing..


Auditing and Hardening: Making Permissions Visible

Permissions are only effective if they are understood and monitored. Three habits keep the permission landscape transparent:

  1. Find world-writable files – A classic vector for privilege escalation.
    find / -xdev -type f -perm -0002 -ls 2>/dev/null
    
  2. Locate setuid/setgid binaries – Review this list after every package update.
    find / -xdev \( -perm -4000 -o -perm -2000 \) -type f -exec ls -ld {} +
    
  3. use stat for the full picture – It reveals ACLs, capabilities, and extended attributes that ls -l hides.
    stat /usr/bin/ping
    # Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
    # Capabilities: cap_net_raw=ep
    

Modern distributions increasingly replace setuid binaries with file capabilities (e.Because of that, , cap_net_raw+ep on ping), granting only the specific kernel privilege required rather than full root authority. Think about it: g. Where capabilities exist, they are preferable to the blunt instrument of setuid.


Conclusion

Linux permissions are not merely a checklist of r, w, and x; they form a layered defense-in-depth strategy. The traditional discretionary access control (DAC) model—user, group, other—provides the baseline. Think about it: special bits (setuid, setgid, sticky) extend that model for specific operational needs like privilege delegation and shared directories. Because of that, filesystem attributes (chattr) add immutability and audit trails below the permission layer. Finally, ACLs and capabilities shatter the coarse three-subject limit, allowing precise, least-privilege grants without sacrificing the simplicity of the underlying model.

And yeah — that's actually more nuanced than it sounds.

Mastering this stack means moving beyond “chmod 777 to make it work” toward intentional design: directories with 2775 and default ACLs for collaboration, logs with +a for integrity, binaries with capabilities instead of setuid, and regular audits that catch drift before it becomes a breach. In a well-governed system, permissions are not obstacles—they are the architecture of trust.

Just Came Out

Hot New Posts

Explore a Little Wider

These Fit Well Together

Thank you for reading about How To Change Permission In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home