Linux File Permissions Explained | Complete Guide with Octal Cheatsheet and Commands

Learn everything about Linux file permissions, including symbolic and octal notations, user-group-other levels, SUID, SGID, Sticky Bit, and chmod usage. This guide includes a visual cheatsheet, best practices, and real command-line examples.

Jun 19, 2025 - 09:35
104.6k
Linux File Permissions Explained |  Complete Guide with Octal Cheatsheet and Commands

Table of Contents

Understanding Linux file permissions is essential for system administrators, ethical hackers, developers, and cybersecurity professionals. Proper file permissions protect sensitive data, prevent unauthorized access, and define who can read, write, or execute files or directories. In this blog, we’ll break down everything from permission notations to special bits like SUID, SGID, and the Sticky Bit, using real-world examples and terminal commands.

What Are Linux File Permissions?

Linux file permissions determine the level of access users have to a particular file or directory. These permissions are assigned to three categories of users:

  • Owner: The user who owns the file

  • Group: Users who belong to the file's group

  • Others: Everyone else

Each of these categories can be assigned three types of permissions:

Permission Symbol Meaning
Read r View file contents or list directory contents
Write w Modify file contents or create/delete files in a directory
Execute x Run a file as a program or enter a directory

 File Permission Structure

A typical Linux permission string looks like:

-rwxr-xr--

Here’s how to read it:

  • First character: - indicates a regular file; d is for directories.

  • Next 3: rwx — Owner permissions (read, write, execute)

  • Next 3: r-x — Group permissions (read, execute)

  • Last 3: r-- — Other permissions (read only)

 Octal (Numeric) Representation of Permissions

Permissions can also be represented in binary or octal:

Binary Octal Symbol Meaning
000 0 --- No permissions
001 1 --x Execute only
010 2 -w- Write only
011 3 -wx Write + Execute
100 4 r-- Read only
101 5 r-x Read + Execute
110 6 rw- Read + Write
111 7 rwx Read + Write + Execute

So a permission string like rwxr-xr-- is 754 in octal.

 Special File Permissions: SUID, SGID, Sticky Bit

Linux offers three special bits that can alter how files are accessed and executed:

 SUID (Set User ID)

Allows users to run an executable with the permissions of the file owner.

  • Symbol: s in the owner execute field

  • Example: -rwsr-xr-x

  • Command:

    chmod u+s filename
    

 SGID (Set Group ID)

Files: Similar to SUID, but applies to group permissions.
Directories: Newly created files inherit the group of the directory.

  • Symbol: s in the group execute field

  • Example: -rwxr-sr-x

  • Command:

    chmod g+s directory
    

Sticky Bit

Applied to directories to restrict file deletion within them to file owners.

  • Symbol: t in the other execute field

  • Example: drwxrwxrwt

  • Command:

    chmod +t directory
    

 Changing Permissions Using chmod

Linux provides the chmod command to change permissions in both symbolic and octal format.

✅ Symbolic Example:

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

✅ Octal Example:

chmod 755 filename     # rwxr-xr-x
chmod 700 filename     # rwx------
chmod 644 file.txt     # rw-r--r--

 Viewing Permissions with ls -l

ls -l

Sample Output:

-rwxr-xr-- 1 user group  2048 Jun 19 12:30 example.sh

Breakdown:

  • -rwxr-xr--: Permissions

  • 1: Number of hard links

  • user: File owner

  • group: File’s group

  • 2048: File size in bytes

  • Jun 19 12:30: Last modified

  • example.sh: Filename

 Best Practices for Managing Permissions

  • Always follow the principle of least privilege.

  • Avoid using 777 unless absolutely necessary.

  • Use SUID/SGID/Sticky Bit carefully to avoid privilege escalation.

  • Use groups to manage multiple users with similar permissions.

✅ Common Permission Use Cases

Use Case Command
Make script executable chmod +x script.sh
Make file read-only chmod 444 filename.txt
Allow full access chmod 777 testfile
Secure config file chmod 600 config.ini
Set SUID chmod u+s /path/to/file
Set SGID chmod g+s /path/to/dir
Set Sticky Bit chmod +t /tmp/shared_dir

 Conclusion

Linux file permissions are one of the foundational elements of system security. With a deep understanding of permission notations, octal values, and special bits like SUID, SGID, and the Sticky Bit, you'll be equipped to secure any Linux environment effectively. Use the cheatsheet provided to reinforce your knowledge and apply best practices for file access control.

FAQs

Read (r), Write (w), and Execute (x).

It sets permissions to rwxr-xr-x, allowing full access for the owner, read-execute for group and others.

Symbolic uses letters like rwx, while octal uses numbers like 755.

Use the chmod command.

Set User ID allows users to execute a file with the file owner's privileges.

Use: chmod u+s filename

SGID allows files in a directory to inherit the directory’s group.

Use: chmod +t folder_name

Gives all permissions (read, write, execute) to everyone—it's risky.

Use: ls -l

It means owner can read/write/execute, group can read/execute, others can only read.

Yes, directories often need execute (x) permission to allow traversal.

The user who created or owns the file.

Use: chmod o=r filename

Grants read/write to owner, denies all access to group and others.

It allows anyone to modify or execute the file—potential security risk.

Use: chmod -R 755 /directory

Adds execute permission to the specified user or group.

Adds read permission for all (user, group, others).

Use: chmod o-w filename

Restricts file deletion in shared directories to only the file's owner.

Directory with read, write, execute for all and a Sticky Bit set.

Use: chmod +x script.sh

Typically 644 for files and 755 for directories.

Read-only for all.

Yes, using chown for ownership and chmod for permissions.

Use: chmod a+x filename

775 gives write permission to the group, 755 does not.

Use: chmod 700 filename

Example: chmod u+x,g-w filename

Yes. Lack of execute permission will prevent a script or binary from running.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.