Linux File Permissions Explained

Linux file permissions control who can read, modify, or execute files and directories. Understanding permissions is essential for managing Linux systems securely and preventing unauthorized access.

What are Linux File Permissions?

Linux assigns permissions to files and directories based on the owner, group, and other users. Each permission determines what a particular user category can do with a resource.

TEXT
-rwxr-xr-- 1 user developers 2048 app.sh

Types of Linux Permissions

  • Read (r) allows a file to be viewed
  • Write (w) allows a file to be modified
  • Execute (x) allows a file to be executed

Linux Permission Categories

  • User represents the file owner
  • Group represents users assigned to the file group
  • Others represents all remaining users

How to Check File Permissions

The ls -l command displays file permissions, ownership, size, and other information.

BASH
ls -l

-rw-r--r-- 1 user developers 1200 notes.txt

Understanding Permission Notation

TEXT
rwx | r-x | r--
User  Group  Others

The first permission group applies to the owner, the second applies to the group, and the third applies to other users.

Using chmod

The chmod command changes file and directory permissions.

BASH
chmod 755 script.sh
chmod u+x script.sh
chmod 644 notes.txt

Numeric Linux Permissions

PermissionValueMeaning
Read4View or read data
Write2Modify data
Execute1Execute or access
None0No permission

Common chmod Examples

BASH
chmod 600 private.txt
chmod 644 document.txt
chmod 755 script.sh
chmod 700 secure-folder

Using chown

The chown command changes the owner and group associated with a file or directory.

BASH
sudo chown alice file.txt
sudo chown alice:developers file.txt

File Permissions vs Directory Permissions

PermissionFileDirectory
ReadView contentsList contents
WriteModify contentsCreate or delete entries
ExecuteRun the fileEnter/access the directory

Common Permission Examples

  • 644 is commonly used for regular files
  • 755 is commonly used for executable scripts and directories
  • 600 restricts access to the owner
  • 700 gives full access only to the owner

Common Mistakes to Avoid

  • Using chmod 777 unnecessarily
  • Changing ownership without understanding the impact
  • Giving write access to too many users
  • Ignoring sensitive configuration files
  • Running every command as root

Advanced Linux Permission Concepts

  • Special permissions
  • Setuid
  • Setgid
  • Sticky bit
  • Access Control Lists
  • Default directory permissions

Practice Exercises

  • Create a file and inspect its permissions
  • Change permissions using chmod
  • Change ownership using chown
  • Create a shared directory for a group
  • Practice restrictive permissions on sensitive files

Conclusion

Linux file permissions provide a simple but powerful mechanism for controlling access to files and directories. Learning chmod, chown, ownership, and permission notation is essential for Linux administration and system security.

Note: Note: Use the least permissions necessary. Avoid broad permissions such as 777 unless there is a specific and well-understood reason.