Linux/Unix Tutorial
Estimated reading: 3 minutes 43 views

πŸ“‘ 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, and chgrp
  • How the umask affects default permissions
  • How to use and modify environment variables (env, printenv)

πŸ“˜ Topics Covered

πŸ”΅ SubtopicπŸ“– Description
Linux/Unix: File Permissions / ls -lLearn how to read permission bits and understand user/group/other access rights
Linux/Unix: chmod, chown, chgrp, umaskModify 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:

SymbolMeaning
-Regular file (use d for 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:

NumberSymbolPermission
7rwxRead + Write + Exec
6rw-Read + Write
5r-xRead + Exec
4r–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 -l to inspect permission settings
  • chmod modifies permissions; chown/chgrp change ownership
  • umask controls default permissions for new files
  • env and export manage 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 .bashrc or 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

πŸ“‘Linux/Unix: Permissions & Ownership

Or Copy Link

CONTENTS
Scroll to Top