π Linux/Unix: Permissions & Ownership β Manage Access with chmod, chown, umask & env
π§² Introduction β Why Permissions & Ownership Matter in Linux
Linux is a multi-user system with robust security built right into its file permission model. Understanding how to manage who can read, write, and execute files is essential for both developers and sysadmins. This guide covers the tools and concepts behind file permissions, user ownership, and environment variables.
π― In this guide, youβll learn:
- How to read and understand Linux file permissions using ls -l
- How to change permissions and ownership with chmod,chown, andchgrp
- How the umaskaffects default permissions
- How to use and modify environment variables (env,printenv)
π Topics Covered
| π΅ Subtopic | π Description | 
|---|---|
| Linux/Unix: File Permissions / ls -l | Learn how to read permission bits and understand user/group/other access rights | 
| Linux/Unix: chmod, chown, chgrp, umask | Modify access control and ownership using essential commands | 
| Linux/Unix: Environment Variables (env, printenv) | View and set shell variables that affect user sessions and scripts | 
π΅ Linux/Unix: File Permissions / ls -l
πΉ Basic Structure of File Permissions
Use ls -l to see file permissions:
ls -l
β Sample Output:
-rw-r--r-- 1 user group 1024 Jun 7 12:00 example.txt
π Breakdown:
| Symbol | Meaning | 
|---|---|
| - | Regular file (use dfor directory) | 
| rw- | User (owner): read + write | 
| r-- | Group: read only | 
| r-- | Others: read only | 
π΅ Linux/Unix: chmod, chown, chgrp, umask
πΉ chmod β Change File Permissions
chmod 755 script.sh
β This gives:
- Owner: read/write/execute
- Group & Others: read/execute
π’ Numeric Permissions:
| Number | Symbol | Permission | 
|---|---|---|
| 7 | rwx | Read + Write + Exec | 
| 6 | rw- | Read + Write | 
| 5 | r-x | Read + Exec | 
| 4 | r– | Read only | 
π€ Symbolic Method:
chmod u+x filename   # Add execute permission to owner
chmod g-w file.txt   # Remove write permission from group
πΉ chown β Change Ownership
chown john file.txt
β
 Changes owner to john.
chown john:devteam file.txt
β Changes owner and group.
πΉ chgrp β Change Group
chgrp admin file.txt
β
 Assigns file to admin group.
πΉ umask β Set Default Permission Mask
umask
β
 Shows current mask (e.g., 0022)
π§ Explanation:
umask subtracts permissions from default (666 for files, 777 for directories).
E.g., umask 022 β Files created with 644, Directories with 755
π΅ Linux/Unix: Environment Variables (env, printenv)
Environment variables define session-specific data like $HOME, $PATH, or custom flags.
πΉ View All Variables
env
printenv
β Lists all variables.
πΉ View Specific Variable
echo $HOME
printenv PATH
β Shows individual values.
πΉ Set Environment Variable
export MY_VAR="hello"
β Temporarily sets a variable in the current session.
π Summary β Recap & Next Steps
Linux file permissions and ownership controls form the backbone of secure, multi-user environments. Mastering chmod, chown, and umask ensures you can protect files, share them wisely, and manage access like a pro.
π Key Takeaways:
- Use ls -lto inspect permission settings
- chmodmodifies permissions;- chown/- chgrpchange ownership
- umaskcontrols default permissions for new files
- envand- exportmanage environment variables that affect shell behavior
βοΈ Practical Use Cases:
- Secure files by limiting access to sensitive config files
- Collaborate on shared directories using groups and symbolic permissions
- Automate setups using environment variables in .bashrcor scripts
β Frequently Asked Questions
β How can I give only the owner full permissions in Linux?
β
 Use:
chmod 700 filename
This gives rwx------ permissions.
β What is the difference between chmod 755 and chmod 644?
β
 755 allows execute permission for all; 644 restricts it to read/write for owner, read-only for others.
β How do I change both user and group ownership?
β
 Use:
chown user:group filename
β What does umask 022 mean?
β
 It masks write permissions for group/others. Files will default to 644, directories to 755.
Share Now :
