Understanding File Permissions in Linux – A Beginner’s Guide

The foundation of Linux systems' security model is file permissions. They decide who can access a system's files and directories and how. An overview of Linux file permissions, their operation, and how to modify them are given in this article.

File permissions in Linux control who can read, write, or execute a file. Understanding these permissions is essential for system security, user management, and smooth application operation. In this guide, you’ll learn what Linux file permissions are, how they work, and how to change them with simple commands.

A fundamental security aspect of Linux is permissions, which regulate who can access, alter, or run files and folders. The owner, the group, and others (everyone else) are the three user classes to which they are assigned.

understanding linux file permissions rwx r-x r-x


What Are File Permissions in Linux?

Every file and directory in Linux has permissions that define:

  • Who can read it

  • Who can modify it

  • Who can execute it

These permissions are divided into three categories:

  1. Owner – the user who created the file

  2. Group – users in the same group

  3. Others – everyone else


Types of Permissions

Linux uses three main permission types:

  • Read (r) – view file content

  • Write (w) – modify or delete file

  • Execute (x) – run file as a program


Viewing File Permissions

Use the ls -l command:

ls -l file.txt

Example output:

-rw-r--r-- 1 user group 1200 Jan 18 file.txt

Breakdown:

  • - : file type

  • rw- : owner permissions

  • r-- : group permissions

  • r-- : others permissions


Understanding Permission Format

Format:

rwxr-xr--

Meaning:

  • Owner: rwx (read, write, execute)

  • Group: r-x (read, execute)

  • Others: r-- (read only)


File vs Directory Permissions

For files:

  • r → read file

  • w → edit file

  • x → run file

For directories:

  • r → list files

  • w → add/delete files

  • x → enter directory


Changing Permissions with chmod

Using Symbolic Mode

chmod u+x file.sh      # add execute to owner
chmod g-w file.txt     # remove write from group
chmod o+r file.txt     # add read to others

Using Numeric Mode

Numbers:

  • r = 4

  • w = 2

  • x = 1

Example:

chmod 755 script.sh

Meaning:

  • Owner: 7 → rwx

  • Group: 5 → r-x

  • Others: 5 → r-x


Changing Owner and Group

Use chown:

chown user file.txt
chown user:group file.txt

Special Permissions

SUID (Set User ID)

chmod u+s file

File runs with owner’s permissions.


SGID (Set Group ID)

chmod g+s dir

Files inside inherit group.


Sticky Bit

chmod +t /shared

Only file owner can delete files.


Common Permission Examples

CommandMeaning
chmod 644 file.txtOwner read/write, others read
chmod 700 privateOnly owner access
chmod 777 fileEveryone full access (not recommended)

Why File Permissions Matter

File permissions:

  • Protect sensitive data

  • Prevent unauthorized access

  • Control program execution

  • Improve system security

Wrong permissions can lead to data loss or hacking.


Conclusion

Understanding file permissions in Linux is essential for every user and administrator. Permissions define who can read, write, or execute files and directories. By learning commands like ls, chmod, and chown, you can manage security and access effectively in any Linux system.

Comments

Popular posts from this blog

How to Improve Node.js Performance (100% Working Techniques)

Top 10 Linux File System Basics – A Complete for Beginners