Mastering Linux File Permissions

Linux file permissions are essential to both user administration and system security. There is a whole world of sophisticated permission management that offers you greater control and security over your files and directories, even though many developers are familiar with the fundamental chmod commands. This manual is intended for developers, system administrators and inquisitive students who wish to learn more about Linux file permissions and go beyond the fundamentals. Introduction to File Permissions Linux is an operating system that supports numerous users. A file permission scheme is used to specify who can read, write, or execute a file or directory in order to maintain security and control. Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8 d rwxr-xr-x. 2 root root 6 May 10 17:54 dir1 - rw-r--r--. 1 root root 2662 May 10 17:55 file1 Field 1: file/dir types [-,d,l,c,s,p,b] Field 2: file/dir permission (user+group+others+acl) Field 3: file/dir link - For a file the link value will be 1 and for a directory it will be 2 by default. However, for a directory the value will depend on the number of directories it contains. Field 4: file/dir owner - who creates the file. Field 5: file/dirgroup owner Field 6: file/dir size - in bytes (1024 bytes = 1KB) Field 7: file/dir modify date Field 8: file/dir name Example: Here is a basic file permission field. - rw- r-- r-- . There are 11 sub fields exist. Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8 Field 9 Field 10 Field 11 -/d r w - r - - r - - . Understanding the Permission Every file or directory in Linux has three types of permissions: Read (r): View file contents or list directory Write (w): Modify file contents or add/remove files in directory Execute (x): Run the file as a program or enter a directory These are applied to three user categories: Symbol Category u User (Owner) g Group o Others (Everyone) Example -rwxr-xr-- 1 user group 1234 Jan 1 12:00 cmd.sh Explanation User: rwx (read, write, execute) Group: r-x (read, execute) Others: r-- (read only) Symbolic vs Numeric Permissions Permissions can be set using symbolic notation or numeric (octal) values. Symbolic Numeric Meaning rwx 7 Read + Write + Execute rw- 6 Read + Write r-x 5 Read + Execute r-- 4 Read only --- 0 No permissions Examples: chmod 755 script.sh # rwxr-xr-x chmod u+x filename # Add execute for user chmod g-w,o-w file.txt # Remove write for group and others Conclusion The ability to comprehend Linux file permissions is essential for maintaining the security and organization of your system; it's not just a box to check. Let’s Connect If you found this helpful: Share it on dev.to Reach out or connect on LinkedIn Follow for more Linux & DevOps tips!

May 4, 2025 - 17:12
 0
Mastering Linux File Permissions

Linux file permissions are essential to both user administration and system security. There is a whole world of sophisticated permission management that offers you greater control and security over your files and directories, even though many developers are familiar with the fundamental chmod commands.

This manual is intended for developers, system administrators and inquisitive students who wish to learn more about Linux file permissions and go beyond the fundamentals.

Introduction to File Permissions

Linux is an operating system that supports numerous users. A file permission scheme is used to specify who can read, write, or execute a file or directory in order to maintain security and control.

Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8
d rwxr-xr-x. 2 root root 6 May 10 17:54 dir1
- rw-r--r--. 1 root root 2662 May 10 17:55 file1
  1. Field 1: file/dir types [-,d,l,c,s,p,b]
  2. Field 2: file/dir permission (user+group+others+acl)
  3. Field 3: file/dir link - For a file the link value will be 1 and for a directory it will be 2 by default. However, for a directory the value will depend on the number of directories it contains.
  4. Field 4: file/dir owner - who creates the file.
  5. Field 5: file/dirgroup owner
  6. Field 6: file/dir size - in bytes (1024 bytes = 1KB)
  7. Field 7: file/dir modify date
  8. Field 8: file/dir name

Example:
Here is a basic file permission field.

- rw- r-- r-- .

There are 11 sub fields exist.

Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8 Field 9 Field 10 Field 11
-/d r w - r - - r - - .

Understanding the Permission

Every file or directory in Linux has three types of permissions:

  • Read (r): View file contents or list directory
  • Write (w): Modify file contents or add/remove files in directory
  • Execute (x): Run the file as a program or enter a directory

These are applied to three user categories:

Symbol Category
u User (Owner)
g Group
o Others (Everyone)

Example

-rwxr-xr--  1 user group 1234 Jan 1 12:00 cmd.sh

Explanation

  • User: rwx (read, write, execute)
  • Group: r-x (read, execute)
  • Others: r-- (read only)

Symbolic vs Numeric Permissions

Permissions can be set using symbolic notation or numeric (octal) values.

Symbolic Numeric Meaning
rwx 7 Read + Write + Execute
rw- 6 Read + Write
r-x 5 Read + Execute
r-- 4 Read only
--- 0 No permissions

Examples:

chmod 755 script.sh    # rwxr-xr-x
chmod u+x filename     # Add execute for user
chmod g-w,o-w file.txt # Remove write for group and others

Conclusion

The ability to comprehend Linux file permissions is essential for maintaining the security and organization of your system; it's not just a box to check.

Let’s Connect

If you found this helpful:

Share it on dev.to
Reach out or connect on LinkedIn
Follow for more Linux & DevOps tips!