In Linux, file permissions determine who can access a file or directory, and what actions they can perform on it.
for example: Create a simple file and do ls -ltr
to see the details of the files.
There are three types of permissions: read (r), write (w), and execute (x), and there are three categories of users: owner, group, and others.
owner -is the user who created the file or directory.
group- is a collection of users who share some common characteristics.
others - are all users with access to the system.
Permission with numeric and symbol
To modify file permissions in Linux, you can use the chmod command, followed by the permission string and the name of the file or directory.
for example: Give read, write, execute
permissions to the owner
of file.txt
Additionally, you can use numerical values to represent permissions.
For change ownership: chown
is used to change the ownership permission of a file or directory. Syntax : chown <user_name> <file_name>
example : chown
afsha file.txt
for change group ownership: chgrp is used to change the group permission of a file or directory. Syntax : chgrp <group_name> <file_name>
example: chgrp devops file.txt
Access Control List
Access Control list is used for providing special permissions to a specific user and group to particular directories and file without changing the base ownership and permission.
\>>To view the ACLs for a file or directory, use the command getfacl.
Syntax: getfacl <name of the file or directory>
eg: getfacl file.txt
\>>To set ACL permission to user, use the command setfacl.
eg: setfacl -m u:afsha:rwx file.txt
\>>To remove ACL permission of user.
eg: setfacl -x u:afsha: file.txt
\>>To set ACL permission to group.
setfacl -m g:devops:rw file.txt
\>>To remove ACL permission of group.
setfacl -x g:devops file.txt