Explore how Linux assigns ownership through users and groups for flexible access control.
Save
Understand why Linux treats everything as a file and how this impacts permissions.
Save
Linux doesn't just ask "who owns this file?" - it asks "which user owns this file and which group owns this file?"
Every file has two owners:
Why two owners? Imagine you're working on a project with your team:
Real Example:
When you create a file called test.txt
:
nana
(you)nana
(your primary group)The Power: This dual ownership system lets you create sophisticated access controls. You can give yourself full access, your team partial access, and everyone else limited access - all for the same file!
In Linux, there's a fundamental principle that might sound strange at first: everything is a file.
This means your keyboard, mouse, hard drive, network connections, and even directories are all treated as files by the Linux system. This unified approach makes Linux incredibly powerful and consistent.
Why does this matter for permissions? Since everything is a file, the same permission system applies to:
The Big Picture: Understanding that everything is a file helps explain why Linux has such a comprehensive and consistent permission system. Every single thing in your Linux system can be secured and controlled using the same set of rules.
This is why mastering file permissions isn't just about protecting documents - it's about understanding how Linux secures your entire system!
Learn how to reveal the hidden permission details of every file and folder.
You already know ls
shows files and ls -a
shows hidden files. But there's a third flag that reveals the secret life of your files: ls -l
When you run ls -l
, suddenly each file displays a cryptic string of letters and dashes:
This isn't random gibberish - it's a permission blueprint that tells you:
Pro Tip: Want to see permissions for hidden files too? Combine the flags: ls -la
The Revelation: Every file in Linux has been quietly carrying this detailed security information all along. The ls -l
command is like putting on X-ray glasses to see the permission structure that's always been there, silently protecting your system.
Save
Crack the code of the cryptic permission string that controls file access.
Save
Let's decode this mysterious string: -rwxr-xr--
First Character - File Type:
-
= Regular filed
= Directoryl
= Link (we'll learn about these later)Next 9 Characters - Permissions (3 blocks of 3):
Block 1 (positions 2-4): User Owner Permissions
r
= Read (can view file contents)w
= Write (can edit/modify file)x
= Execute (can run the file as a program)Block 2 (positions 5-7): Group Owner Permissions
r
, w
, x
meanings, but for the groupBlock 3 (positions 8-10): Everyone Else Permissions
r
, w
, x
meanings, but for all other usersExample Breakdown:
-rwxr-xr--
means:
-
= Regular filerwx
= User owner can read, write, and executer-x
= Group owner can read and execute (but not write)r--
= Everyone else can only readThe Dash Rule: A dash (-
) means "permission denied" for that specific action.
Understand what read, write, and execute permissions actually mean in practice.
Save
Learn about the 'other' category that controls access for all remaining users.
Save
Discover the shorthand system that lets you set all permissions with just three digits.
Save
Master the intuitive method of adding and removing specific permissions.
Save
Linux has exactly three permission types, but their meaning changes depending on whether you're dealing with files or directories.
For Regular Files:
Read (r) - "Can I see what's inside?"
Write (w) - "Can I change it?"
Execute (x) - "Can I run it?"
For Directories:
Read (r) - "Can I list what's inside?"
Write (w) - "Can I modify the contents?"
Execute (x) - "Can I enter this directory?"
cd
command)Important: You need execute permission on a directory to access files inside it, even if you have read permission on those files!
We've covered user owners and group owners, but who is the mysterious third owner?
Meet "Other" - this represents everyone else on the system who isn't:
Why is this important? Linux systems often have multiple users:
Example Scenario:
File owned by user nana
and group developers
:
developers
group get the second blockReal Permission String:
-rw-r--r--
means:
rw-
= nana can read and writer--
= developers group can only readr--
= everyone else can only readSecurity Principle: The "other" category is your safety net. It defines the minimum level of access that any user on the system could potentially have to your file.
Typing chmod u+r,g+w,o-x
gets tedious. Linux offers a shortcut: numeric permissions.
The Magic Numbers: Each permission has a value:
r
(read) = 4w
(write) = 2x
(execute) = 1How it works: Add the numbers for each permission block:
rwx
= 4+2+1 = 7 (all permissions)rw-
= 4+2+0 = 6 (read and write)r-x
= 4+0+1 = 5 (read and execute)r--
= 4+0+0 = 4 (read only)-wx
= 0+2+1 = 3 (write and execute)-w-
= 0+2+0 = 2 (write only)--x
= 0+0+1 = 1 (execute only)---
= 0+0+0 = 0 (no permissions)Common Examples:
Memory Trick: 644 is the most common permission for regular files, 755 for executable files and directories.
The chmod
(change mode) command is your tool for modifying permissions. The symbolic method is intuitive and precise.
Basic Syntax:
chmod [who][action][permission] filename
Who:
u
= User ownerg
= Group ownero
= Other usersa
= All (user + group + other)Action:
+
= Add permission-
= Remove permission=
= Set exact permissionsPermission:
r
= Readw
= Writex
= ExecutePractical Examples:
Pro Tip: You can combine actions: chmod u+x,g-w,o=r filename
Learn how to view and modify permissions for hidden files and system files.
Save
Master the commands that transfer file ownership between users and groups.
Save
Hidden files (those starting with .
) have permissions too, but ls -l
won't show them by default.
Revealing Hidden File Permissions:
Common Hidden Files You'll Encounter:
.bashrc
- Your shell configuration.ssh/
- SSH keys and config.gitconfig
- configuration.vimrc
- Vim editor settingsTypical Hidden File Permissions:
Security Note: Hidden files often contain sensitive configuration or private keys. They typically have restrictive permissions (600 or 700) to prevent unauthorized access.
Modifying Hidden File Permissions:
Remember: Hidden files follow the same permission rules as regular files - they're just not displayed by default.
What if you need to transfer ownership of a file? Linux provides powerful commands to change who owns what.
The chown
Command (Change Owner)
The chgrp
Command (Change Group)
Why sudo
?
Changing ownership is a powerful operation that affects system security, so you need administrator privileges.
Real-World Scenario: Imagine you created a configuration file but now need to hand it over to the system administrator (root) and the admin group:
Key Insight: Ownership changes are permanent and immediate. The moment you run these commands, the file belongs to its new owners with all the rights and restrictions that come with that ownership.