Linux File Permissions Explained: chmod, chown, and umask

Linux file permissions control who can read, write, and execute files and directories.

Understanding permissions is essential for system administration, security, and everyday Linux usage.

This guide explains Linux file permissions, ownership, chmod, chown, and umask with practical examples.

Concept Overview

Every file and directory in Linux has permissions that determine access for the owner, group, and others.

Permissions help protect sensitive data while allowing authorized users to perform necessary tasks.

Understanding Permission Types

1. Read (r) – Allows viewing the contents of a file or listing a directory.

2. Write (w) – Allows modifying a file or creating/removing files inside a directory.

3. Execute (x) – Allows running a file as a program or accessing a directory.

Permission Categories

1. User (u) – The owner of the file.

2. Group (g) – Users belonging to the assigned group.

3. Others (o) – All remaining users.

4. All (a) – Represents user, group, and others together.

Essential Commands

1. ls -l – Display file permissions and ownership.

2. chmod – Change file or directory permissions.

3. chown – Change file ownership.

4. chgrp – Change group ownership.

5. umask – Set default permissions for newly created files and directories.

Examples

BASH
ls -l
chmod 755 script.sh
chmod u+x script.sh
chmod go-w file.txt
chown john file.txt
chown john:developers project/
chgrp developers project/
umask
umask 022

Detailed Explanation

The ls -l command displays permission bits, owner, group, file size, and modification date.

The chmod command modifies permissions using either symbolic notation (u, g, o) or numeric values like 755 and 644.

The chown command changes the ownership of files and directories.

The chgrp command updates the group associated with a file or directory.

The umask command defines default permissions when new files and directories are created.

Numeric Permission Values

4 represents Read, 2 represents Write, and 1 represents Execute.

For example, 7 = rwx (4+2+1), 6 = rw-, 5 = r-x, and 4 = r--.

Common permissions include 755 for executable programs and directories, and 644 for regular files.

Example Walkthrough

Create a shell script and grant execute permission using chmod +x or chmod 755.

Use ls -l to verify the updated permissions.

Change the file owner with chown and confirm the changes using ls -l.

Check the current umask value and understand how it affects newly created files.

Applications

Used to secure Linux servers, manage shared project directories, and protect sensitive files.

Essential knowledge for Linux administrators, DevOps engineers, and developers.

Advantages

Provides strong access control for files and directories.

Helps prevent unauthorized access and accidental modifications.

Supports secure collaboration through user and group ownership.

Limitations

Incorrect permissions can block legitimate users or expose sensitive data.

Managing permissions becomes more complex in large multi-user environments.

Best Practices

Follow the principle of least privilege by granting only the permissions that are required.

Avoid giving write permissions to others unless absolutely necessary.

Regularly audit file ownership and permissions on critical systems.

Learn Access Control Lists (ACLs) for more advanced permission management.

Mastering Linux file permissions is a fundamental skill for maintaining secure and reliable Linux systems.