Agentic AI with Java: Live Cohort
LinuxLinux Users, Permissions & Ownership

Linux File Permissions - Symbolic Mode

Linux is a multi-user operating system where multiple users and applications may access the same system. File permissions control who can read, modify, or execute files and who can access directories.

They help protect sensitive data, prevent unauthorized changes, and maintain control over system resources.

Linux_Permissions

Important: For directories, x means search or traverse permission. It allows a user to access entries inside the directory when the necessary permissions are available.


Categories of Users

Permissions are assigned to three categories:

CategorySymbolDescription
Owner (User)uThe user who owns the file
GroupgUsers belonging to the file's associated group
OthersoEveryone who is neither the owner nor a member of the associated group

Linux evaluates these categories when determining whether a user can perform an operation on a file or directory.


Understanding Permission Strings

Run ls -l to view file permissions and other details.

ls -l

Example output:

-rw-rw-r-- 1 ubuntu ubuntu 120 Oct 11 10:30 ai.txt

The permission string is -rw-rw-r--. It contains ten characters.

PositionExampleMeaning
1-File type: - means regular file; d means directory
2–4rw-Owner permissions
5–7rw-Group permissions
8–10r--Others' permissions

Let's break it down:

- rw- rw- r--
  │   │   │
  │   │   └── Others: read only
  │   └────── Group: read and write
  └────────── Owner: read and write

The leading character identifies the file type. Other types may use characters such as l for a symbolic link.

More Examples

Permission StringOwnerGroupOthers
-rw-rw-r--Read, writeRead, writeRead
-rw-r--r--Read, writeReadRead
-rwxrw-r--Read, write, executeRead, writeRead
-rwxrwxrwxAll threeAll threeAll three

Changing Permissions with chmod

The chmod command changes file or directory permissions. In this lecture, we use symbolic mode, which lets you add or remove specific permissions without replacing the entire permission set.

Syntax

chmod [who][operator][permissions] filename
  • who : u (owner), g (group), o (others), or a (all categories).
  • Operator : + adds permissions, - removes them, and = sets the permissions for the specified category.
  • Permissions : r (read), w (write), x (execute).

Adding Permissions (+)

1. Add Execute Permission to the Owner

chmod u+x ai.txt

Adds execute permission for the owner.

Before: -rw-rw-r--
After:  -rwxrw-r--

2. Add Write Permission to Others

chmod o+w ai.txt

Adds write permission for users outside the owner and group categories.

Before: -rwxrw-r--
After:  -rwxrw-rw-

Be careful when granting write permission to others, as it allows those users to modify the file.

3. Add Execute Permission to the Group

chmod g+x aliens.txt

Adds execute permission for the file's group.

Before: -rw-rw-r--
After:  -rw-rwxr--

Removing Permissions (-)

1. Remove Execute Permission from the Owner

chmod u-x alien.tf

Removes execute permission from the owner.

Before: -rwxrw-r--
After:  -rw-rw-r--

2. Remove Write Permission from the Group

chmod g-w alien.tf

Removes write permission from the group.

Before: -rw-rw-r--
After:  -rw-r--r--

3. Remove Read Permission from Others

chmod o-r ai.txt

Removes read permission from others while leaving the owner and group permissions unchanged.


Setting Permissions with =

The = operator sets the permissions for a specified category, replacing its previous permission set.

For example:

chmod u=r file.txt

The owner receives read permission only. Any existing owner write or execute permissions are removed.

To give the owner read and write permissions, the group read permission, and others no permissions:

chmod u=rw,g=r,o= file.txt

The resulting permission string is:

-rw-r-----

Quick Reference

CommandAction
chmod u+x fileAdd execute permission to the owner
chmod u-x fileRemove execute permission from the owner
chmod g+x fileAdd execute permission to the group
chmod g-w fileRemove write permission from the group
chmod o+w fileAdd write permission for others
chmod o-r fileRemove read permission from others
chmod a+r fileAdd read permission for all categories
chmod u=rw,g=r,o= fileSet exact permissions for each category

Summary

  • Linux permissions control access for the owner, group, and others.
  • The three basic permissions are read (r), write (w), and execute (x).
  • Use ls -l to inspect permissions.
  • Use chmod with symbolic mode to modify permissions.
  • + adds permissions, - removes permissions, and = replaces permissions for the specified category.
  • Be cautious when granting write or execute permissions, especially to others.

Remember: File permissions help protect your Linux system. Grant only the access that users and applications actually need.

Written By: Muskan Garg

How is this guide?

Last updated on