Day 6 : Linux File Permissions
Understanding Linux File Permissions
File permissions in Linux are crucial for securing and managing access to files and directories. Here's a simple explanation of how they work and how you can manage them.
Categories of Users
Owner: The user who created the file or directory.
Group: A group of users who share similar permissions.
Others: All other users on the system.
Permission Types
Each file or directory has three types of permissions:
Read (r): Allows viewing the content of a file or listing the contents of a directory.
Write (w): Allows modifying the content of a file or adding/removing files in a directory.
Execute (x): Allows running a file as a program or entering a directory.
Viewing Permissions
To view the permissions of a file, use the ls -ltr
command:
ls -ltr filename
The output will show the permissions in a string like -rwxr-xr--
. Here’s a breakdown:
The first character indicates the type (
-
for file,d
for directory).The next three characters (
rwx
) are the permissions for the owner.The middle three characters (
r-x
) are the permissions for the group.The last three characters (
r--
) are the permissions for others.
Changing Permissions
Change Ownership: Use
chown
to change the owner.chown new_owner filename
Change Group: Use
chgrp
to change the group.chgrp new_group filename
Change Permissions: Use
chmod
to change permissions.chmod u+rwx filename # Add read, write, and execute permissions for the owner chmod g-w filename # Remove write permission for the group chmod o=r filename # Set read-only permission for others
Task Example
Create a File:
touch myfile.txt
View Permissions:
ls -ltr myfile.txt
Change Permissions:
chmod u+x myfile.txt # Add execute permission for the owner chmod g+r myfile.txt # Add read permission for the group chmod o-r myfile.txt # Remove read permission for others
View Changes:
ls -ltr myfile.txt
By understanding and using these commands, you can effectively manage who can access and modify your files, ensuring better security and organization within your Linux system.
Subscribe to my newsletter
Read articles from vinod chandra directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by