Day 6 Task: File Permissions and Access Control Lists
In Linux, file permissions control the read, write, and execute access for the user, group, and others. Hereβs a breakdown of how to manage these permissions:
π Using chmod
(Change Mode)
chmod
modifies the permissions of a file or directory.Syntax:
chmod [options] mode file
Key Options:
Numerical Method: Permissions are represented by a three-digit number. For example,
chmod 755 file
sets the read, write, and execute permissions for the owner, and read and execute permissions for group and others.Symbolic Method: Uses letters (
r
,w
,x
,u
,g
,o
,a
) and symbols (+
,-
,=
) to define permissions. E.g.,chmod u+x file
adds execute permission for the user.
π Using chown
(Change Owner)
chown
changes the owner and/or group of a file.Syntax:
chown [options] owner[:group] file
Example Usage:
Change the owner of a file:
chown username file
Change the owner and group:
chown username:group file
π Using chgrp
(Change Group)
chgrp
changes the group ownership of a file.Syntax:
chgrp [options] group file
Example Usage:
- Simply change the group of a file:
chgrp groupname file
- Simply change the group of a file:
Enhancing Security with Access Control Lists (ACLs)
For more granular control over file permissions, Linux supports ACLs. ACLs allow you to specify more detailed permissions for multiple users and groups.
π Understanding ACLs
- What They Do: ACLs provide additional, more flexible permissions for files and directories beyond the standard owner/group/others model.
π οΈ Setting Up ACLs
Using
setfacl
:Modify ACLs: To add or modify an ACL entry:
setfacl -m u:username:rwx file
Remove ACLs: To remove a specific ACL entry:
setfacl -x u:username file
View ACLs: To view the ACLs of a file:
getfacl file
π ACL Entry Components
User Entries:
u:username:perms
Group Entries:
g:groupname:perms
Other Entries:
o:perms
(standard permissions for others)Mask Entries:
m:perms
(the maximum permissions allowed for users and groups specified by ACLs)
Conclusion
Mastering file permissions and ACLs in Linux helps secure your system and allows precise control over who can access and modify files. Whether you're setting basic permissions with chmod
, changing ownership with chown
and chgrp
, or specifying detailed access rules with ACLs, these tools are integral to effective Linux administration. Keep exploring these commands and test them out to become proficient in managing Linux file systems securely and efficiently.
Thank you for reading! Keep Supporting, learning and growing with each other.
Subscribe to my newsletter
Read articles from Vaishnavi Shivde directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vaishnavi Shivde
Vaishnavi Shivde
Aspiring DevOps Engineer | Linux | Git & Github | Shell Scripting | Docker | CI/CD Jenkins | Kubernetes | AWS | Terraform | JIRA | Python |