File Permissions and Ownership in Linux
Understanding File Permissions in Linux. Linux is a multi-user system, and file permissions are at the core of how access is managed. Every file and directory has a set of permissions that determine who can read, write, or execute it. In this article, you’ll learn how to view, understand, and manage file permissions in Linux using ls, chmod, chown, and chgrp. Table of Contents Permission Categories Permission Types Permission Representation Changing Permissions: chmod Symbolic Mode Numeric Mode Changing Ownership: chown and chgrp Permission Pitfalls to Avoid Best Practices Conclusion Let's Connect on LinkedIn Permission Categories There are three types of users that permissions apply to: User (u): The file's owner Group (g): Users who belong to the file's group Others (o): Everyone else on the system Permission Types Each category can have three types of permissions: Read (r): View the contents of a file or list files in a directory Write (w): Modify the file or create/delete files in a directory Execute (x): Run a file (if it’s a script or binary) or access a directory Permission Representation You can view file permissions using the ls -l command: ls -l filename.txt Example Output: -rw-r--r-- Breakdown: "-": Regular file (use d for directory) "rw-": User (owner) can read and write "r--": Group can read only "r--": Others can only read Changing Permissions: chmod The chmod command is used to change file or directory permissions. Symbolic Mode chmod u+x filename # Add execute for user chmod g-w filename # Remove write for group chmod o=r filename # Set read-only for others Numeric Mode Each permission has a numeric value: Read (r) = 4 Write (w) = 2 Execute (x) = 1 Add the values to get the desired permissions. chmod 755 filename Breakdown: 7 (4+2+1) = rwx (Owner) 5 (4+0+1) = r-x (Group) 5 (4+0+1) = r-x (Others) Changing Ownership: chown and chgrp chown: Changes file ownership chgrp: Changes group ownership chown newuser filename chgrp newgroup filename chown newuser:newgroup filename You must use sudo if you're not the file owner. Permission Pitfalls to Avoid Giving 777 permissions makes a file accessible to everyone for everything, a big security risk. A directory without x cannot be accessed, even if it’s readable. Scripts without x won’t run unless you invoke the interpreter: bash script.sh Best Practices Use 644 for regular files : rw-r--r-- Use 755 for scripts and directories : rwxr-xr-x Avoid 777 unless absolutely necessary and temporary Regularly audit permissions on production environments Use group ownership to manage shared directories efficiently Conclusion Stick to best practices, avoid overly permissive settings like 777, and get comfortable using tools like chmod, chown, and ls -l. Let’s connect on LinkedIn (https://www.linkedin.com/in/chiamaka-chielo?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app) As I automate my journey into RHCE and Ansible, I’d love to connect with fellow learners and professionals. Feel free to reach out and join me as I share tips, resources, and insights throughout this 30-day challenge. cloudwhistler #30daysLinuxchallenge

Understanding File Permissions in Linux.
Linux is a multi-user system, and file permissions are at the core of how access is managed.
Every file and directory has a set of permissions that determine who can read, write, or execute it. In this article, you’ll learn how to view, understand, and manage file permissions in Linux using ls
, chmod
, chown
, and chgrp
.
Table of Contents
- Permission Categories
- Permission Types
- Permission Representation
- Changing Permissions: chmod
- Symbolic Mode
- Numeric Mode
- Changing Ownership: chown and chgrp
- Permission Pitfalls to Avoid
- Best Practices
- Conclusion
- Let's Connect on LinkedIn
Permission Categories
There are three types of users that permissions apply to:
- User (u): The file's owner
- Group (g): Users who belong to the file's group
- Others (o): Everyone else on the system
Permission Types
Each category can have three types of permissions:
- Read (r): View the contents of a file or list files in a directory
- Write (w): Modify the file or create/delete files in a directory
- Execute (x): Run a file (if it’s a script or binary) or access a directory
Permission Representation
You can view file permissions using the ls -l
command:
ls -l filename.txt
Example Output:
-rw-r--r--
Breakdown:
"-": Regular file (use d for directory)
"rw-": User (owner) can read and write
"r--": Group can read only
"r--": Others can only read
Changing Permissions: chmod
The chmod command is used to change file or directory permissions.
Symbolic Mode
- chmod u+x filename # Add execute for user
- chmod g-w filename # Remove write for group
- chmod o=r filename # Set read-only for others
Numeric Mode
Each permission has a numeric value:
- Read (r) = 4
- Write (w) = 2
- Execute (x) = 1
Add the values to get the desired permissions.
- chmod 755 filename
Breakdown:
7 (4+2+1) = rwx (Owner)
5 (4+0+1) = r-x (Group)
5 (4+0+1) = r-x (Others)
Changing Ownership: chown and chgrp
- chown: Changes file ownership
chgrp: Changes group ownership
chown newuser filename
- chgrp newgroup filename
- chown newuser:newgroup filename
You must use sudo if you're not the file owner.
Permission Pitfalls to Avoid
Giving 777 permissions makes a file accessible to everyone for everything, a big security risk.
A directory without x cannot be accessed, even if it’s readable.
Scripts without x won’t run unless you invoke the interpreter:
bash script.sh
Best Practices
Use 644 for regular files : rw-r--r--
Use 755 for scripts and directories : rwxr-xr-x
Avoid 777 unless absolutely necessary and temporary
Regularly audit permissions on production environments
Use group ownership to manage shared directories efficiently
Conclusion
Stick to best practices, avoid overly permissive settings like 777, and get comfortable using tools like chmod, chown, and ls -l.
Let’s connect on LinkedIn
As I automate my journey into RHCE and Ansible, I’d love to connect with fellow learners and professionals. Feel free to reach out and join me as I share tips, resources, and insights throughout this 30-day challenge.