Lesson 3.1: Understanding Permissions
In Linux, every file and directory has a set of permissions that control who can read, write, or execute it. Understanding these permissions is fundamental to working securely and effectively with Linux.
Permission Types: The Three Pillars
Linux uses three basic permission types. Let's break them down:
Read Permission (r)
The read permission lets you:
- For files: View the contents of the file
- For directories: List what's inside the directory
Example: Reading a file
This works because you have read permission on myfile.txt.
Write Permission (w)
The write permission lets you:
- For files: Change or delete the file contents
- For directories: Create, delete, or rename files within that directory
Example: Writing to a file
This works because you have write permission on myfile.txt.
Execute Permission (x)
The execute permission lets you:
- For files: Run the file as a program or script
- For directories: Enter the directory (use
cdto navigate into it)
Example: Running a script
This works because you have execute permission on myscript.sh.
Who Gets Permissions? The Three Categories
Permissions are assigned to three categories of users:
Owner (u)
The user who created the file. The owner typically has the most control over the file.
Group (g)
Users who belong to the same group as the file. Groups are useful for team collaboration.
Others (o)
Everyone else on the system who isn't the owner and isn't in the file's group.
Reading Permission Strings
When you use ls -l, you'll see permission strings like this:
Let's break down -rw-r--r--:
- - - File type (regular file)
- rw- - Owner permissions (read, write, no execute)
- r-- - Group permissions (read only)
- r-- - Others permissions (read only)
File Types
The first character tells you the file type:
- - - Regular file
- d - Directory
- l - Symbolic link
- c - Character device
- b - Block device
Permission Matrix
Here's a visual breakdown of how permissions work:
| Category | Read (r) | Write (w) | Execute (x) |
|---|---|---|---|
| Owner | View file contents | Modify file | Run as program |
| Group | View file contents | Modify file | Run as program |
| Others | View file contents | Modify file | Run as program |
Directory Permissions Are Special
Directory permissions work a bit differently than file permissions:
- Read (r) on a directory lets you list its contents with
ls - Write (w) on a directory lets you create, delete, and rename files within it
- Execute (x) on a directory lets you enter it with
cd
Directory Permission Example
Breaking this down:
- d - It's a directory
- rwx - Owner can read, write, and enter the directory
- r-x - Group members can list and enter, but not create files
- --- - Others have no access at all
Common Permission Patterns
Here are some common permission patterns you'll encounter:
Files
- 644 (-rw-r--r--) - Normal text files (owner can read/write, others can read)
- 755 (-rwxr-xr-x) - Executable programs (everyone can execute)
- 600 (-rw-------) - Private files (only owner can read/write)
- 666 (-rw-rw-rw-) - Shared files (everyone can read/write)
Directories
- 755 (drwxr-xr-x) - Most directories (owner has full control, others can enter)
- 700 (drwx------) - Private directories (only owner can access)
- 777 (drwxrwxrwx) - World-writable (avoid this unless necessary!)
Checking Your Own Permissions
You can check what permissions you have on files with these commands:
What's Next?
Now that you understand how permissions work, it's time to learn how to change them! In the next lesson, we'll cover the chmod command and practice modifying permissions.
Key Takeaways
- Linux has three permission types: read (r), write (w), and execute (x)
- Permissions apply to three categories: owner (u), group (g), and others (o)
- Directory permissions work differently than file permissions
- Always use the most restrictive permissions that still allow necessary access
- Use
ls -lto view permissions andls -ldfor directory permissions
Linux 101