Linux Permissions Explained (chmod, chown) with Examples

Linux Permissions:

Linux is known for its powerful security model, and one of its core strengths lies in its permission system. Understanding Linux permissions is essential for anyone working with servers, cybersecurity, or even basic file management. Whether you’re a beginner or advancing your Linux skills, mastering commands like chmod and chown will give you full control over your files and directories.

In this guide, we’ll break down Linux permissions in a simple and practical way, with examples, use cases, and best practices.


What Are Linux File Permissions?

Every file and directory in Linux has a set of permissions that define who can read, write, or execute it.

There are three types of users:

  • Owner (User) – The person who created the file
  • Group – Users who are part of a group
  • Others – Everyone else on the system

And three types of permissions:

  • Read (r) – View contents of a file
  • Write (w) – Modify or delete the file
  • Execute (x) – Run the file as a program

Understanding Permission Structure

Run the command:

ls -l

Example output:

-rwxr-xr-- 1 user group 1024 Jul 6 file.sh

Breakdown:

  • - → File type (d for directory)
  • rwx → Owner permissions
  • r-x → Group permissions
  • r-- → Others permissions

Quick Meaning:

  • Owner: read, write, execute
  • Group: read, execute
  • Others: read only

Numeric (Octal) Permissions Explained

Each permission has a numeric value:

  • Read (r) = 4
  • Write (w) = 2
  • Execute (x) = 1

Combine them:

Permission Value
rwx 7
rw- 6
r-x 5
r– 4

Example:

chmod 755 file.sh

Means:

  • Owner → 7 (rwx)
  • Group → 5 (r-x)
  • Others → 5 (r-x)

chmod Command (Change Permissions)

The chmod command is used to change file or directory permissions.

Syntax:

chmod [options] mode file

Method 1: Using Numeric Mode

Example:

chmod 644 file.txt

Result:

  • Owner → read + write
  • Group → read
  • Others → read

Method 2: Using Symbolic Mode

Format:

chmod [who][operator][permission] file

Where:

  • u = user (owner)
  • g = group
  • o = others
  • a = all

Operators:

  • + → Add permission
  • - → Remove permission
  • = → Set exact permission

Examples:

chmod u+x script.sh

(Add execute permission for owner)

chmod g-w file.txt

(Remove write permission from group)

chmod a+r file.txt

(Add read permission for everyone)


chown Command (Change Ownership)

The chown command is used to change the owner and group of a file.

Syntax:

chown [owner]:[group] file

Examples:

chown shiva file.txt

(Change owner to “shiva”)

chown shiva:developers file.txt

(Change owner and group)

chown :developers file.txt

(Change only group)


Recursive Permissions and Ownership

To apply changes to all files inside a directory:

chmod recursive:

chmod -R 755 myfolder/

chown recursive:

chown -R user:group myfolder/

Use this carefully, especially on system directories.


Practical Examples

1. Make a Script Executable

chmod +x script.sh

Now you can run:

./script.sh

2. Secure a Private File

chmod 600 secrets.txt

Only owner can read and write.


3. Allow Web Server Access

chmod 755 /var/www/html

This allows others to read and execute but not modify.


4. Fix Permission Denied Error

If you see:

Permission denied

Fix it by:

chmod +x filename

or

sudo chown user filename

Special Permissions in Linux

Linux also supports advanced permissions:

1. SUID (Set User ID)

Runs file with owner’s privileges:

chmod u+s file

2. SGID (Set Group ID)

chmod g+s directory

Files inherit group ownership.


3. Sticky Bit

Used in shared directories:

chmod +t /tmp

Only file owner can delete their files.


Best Practices for Linux Permissions

Follow these time-tested principles:

  • Use least privilege – Only give required permissions
  • Avoid 777 – It makes files open to everyone
  • Secure sensitive files – Use 600 or 700
  • Check before changing recursively
  • Use groups wisely for shared access

Common Mistakes to Avoid

  • Giving execute permission to non-executable files
  • Using chmod -R 777 blindly
  • Not checking ownership before troubleshooting
  • Ignoring group permissions

FAQs

1. What does chmod 777 mean?

It gives full permissions (read, write, execute) to everyone. This is unsafe in most cases.


2. What is the difference between chmod and chown?

  • chmod → Changes permissions
  • chown → Changes ownership

3. How do I check file permissions?

Use:

ls -l

4. What does “Permission denied” mean?

It means your user does not have required permissions to access or execute the file.


5. When should I use sudo?

Use sudo when you need administrator privileges to modify system files or ownership.


Conclusion

Linux permissions are the backbone of system security. By understanding how chmod and chown work, you gain precise control over who can access and modify your files.

Start with simple commands, practice on test files, and gradually build confidence. The traditional discipline of setting correct permissions not only protects your system but also reflects a well-organized and secure workflow.

Master these fundamentals, and you’ll find Linux becoming more powerful and intuitive every day.

Also read on : Linux File Mgt  | Ethical Hacking | Most common Linux Commands 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top