The short answer
File permissions in Linux control who can read, write, or execute a file or directory. Each file has three permission sets: owner, group, and others. The three permission types are read (r), write (w), and execute (x), represented numerically as 4, 2, and 1 respectively.
File permissions in Linux are a security mechanism that determines which users can access, modify, or run files and directories on the system. Every file and directory has an associated set of permissions that controls these access rights.
The Three Types of Permissions
Linux recognises three fundamental permission types:
- Read (r): Allows viewing the contents of a file or listing the contents of a directory. Represented by the number 4 in octal notation.
- Write (w): Permits modifying, deleting, or renaming a file, or adding and removing files within a directory. Represented by the number 2.
- Execute (x): Grants the ability to run a file as a program or script, or to access a directory and its contents. Represented by the number 1.
The Three Permission Categories
Permissions are assigned separately to three categories of users:
- Owner (user): The person who created the file or the user assigned as owner.
- Group: A collection of users who share access rights to the file.
- Others (world): Everyone else on the system who is not the owner or in the group.
How Permissions Appear
When you run the command ls -l, permissions display as a ten-character string. The first character indicates the file type (- for regular file, d for directory, l for symbolic link). The remaining nine characters represent permissions in three groups of three: owner, group, and others. For example, -rw-r--r-- means a regular file where the owner can read and write, while group members and others can only read.
Numeric Representation
Permissions can be expressed as three-digit octal numbers. Each digit is the sum of read (4), write (2), and execute (1) permissions for owner, group, and others respectively. Common examples include:
- 755: Owner can read, write, and execute; group and others can read and execute
- 644: Owner can read and write; group and others can read only
- 700: Owner has full control; group and others have no access
Modifying Permissions
The chmod command changes file permissions. You can use symbolic notation (chmod u+x filename adds execute permission for the owner) or numeric notation (chmod 755 filename). The chown command changes file ownership, and chgrp changes the group assignment.
Special Permissions
Beyond basic permissions, Linux includes special permission bits: setuid (4000), setgid (2000), and sticky bit (1000). These provide additional security controls for executable files and shared directories, though their use requires careful consideration of security implications.