File Ownership
Every file has an owner and a group. These determine which permissions apply to whom.
Viewing Ownership
In this output:
aliceis the ownerdevelopersis the group
chown - Change Owner
Change the file's owner:
sudo Required
Changing ownership requires root privileges (sudo), unless you're changing a file you own to a group you're in.
Change Owner and Group Together
The user:group syntax is the most common.
Recursive Ownership Change
-R changes ownership of all files and subdirectories.
chgrp - Change Group
Change only the group:
When to Use Which
chown user:group- When changing bothchown user- Owner onlychgrp group- Group only
Understanding Groups
See Your Groups
Common System Groups
| Group | Purpose |
|---|---|
| sudo | Administrative privileges |
| docker | Run Docker commands |
| www-data | Web server access |
| adm | Read log files |
Real-World Scenarios
Web Server Files
Shared Project Directory
Now any member of developers can create files there.
Fix Permission Issues
After extracting archives or copying files:
Container Volume Permissions
Containers often need specific UID/GID ownership.
What command changes both owner and group of a file?
Quick Reference
| Command | What It Does |
|---|---|
chown user file | Change owner |
chown user:group file | Change owner and group |
chown :group file | Change group only |
chgrp group file | Change group |
-R flag | Recursive (directories) |
Key Takeaways
- Every file has an owner (user) and a group
chownchanges owner (and optionally group)chgrpchanges only the group- Usually requires
sudo - Use
-Rfor directories - Proper ownership is crucial for security
Next: special permissions - SUID, SGID, and sticky bit.