File Permissions and Access Control Lists

Day-6

·

3 min read

Today is more on Reading, Learning, and Implementing File permissions

The concept of Linux File permission and ownership is important in Linux.

Here, we will be working on Linux permissions and ownership and will do tasks on

both of them.

Linux User

A user is the default owner and creator of the file. So this user is called owner as well.

Linux Group

A user-group is a collection of users. Users that belonging to a group will have the same Linux group permissions to access a file/ folder.

You can use groups to assign permissions in a bulk instead of assigning them individually. A user can belong to more than one group as well.

Other

Any users that are not part of the user or group classes belong to this class.

1 . Create a simple file and do ls -ltr to see the details of the files.

As a task, change the user permissions of the file and note the changes after ls -ltr

Ans :- I have modified the permission of new_file.txt with the help of chmod- change mod command.

2 . Write an article about File Permissions based on your understanding from the notes.

Ans :- File permissions control the ability of user and group accounts to view, modify, access, and execute the contents of the files and directories.

Every file or directory has three levels of ownership:

  • User owner (u).

  • Group owner (g).

  • Others (o).

    ***Each level of ownership can be assigned the following permissions:

    • Read (r).

    • Write (w).

    • Execute (x).

Changing File permissions: The File permissions can be changed using the chmod command. Only root, the file owner, or user with sudo privileges can change the permissions of a file.

  • Syntax : chmod permission <file_name>

    For add read permission to owner: chmod u+r <file_name>

    For add read write permission to group: chmod g+rw <file_name>

    for remove read permission to others: chmod o-r <file_name>

For change ownership: chown is used to change the ownership permission of a file or directory. Synax : chown <user_name> <file_name> eg. example : chown sajid_demo.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 devopsgrp_demo.txt

3 . Read about ACL and try out the commands getfacl and setfacl

Ans :- ACL :- It allows you to give a more specific set of permissions to a file or directory without changing the base ownership and permission.

**

setfacl and getfacl** are used for setting up ACL and showing ACL respectively.

For check ACL permission: Syntax . getfacl <name of file or directory> eg. getfacl demo.txt

For set ACL permission to user: Syntax : setfacl -m u:user:permissions /path_to_file eg. setfacl -m u:user1:rwx /devops

For remove ACL permission of user: Syntax : setfacl -x u:user: /path_to_file eg. setfacl -x u:sajid: /devops

For set ACL permission to Group: Syntax : setfacl -m g:group:permissions /path_to_file eg. setfcal -m g:admin:rwx /devops

For remove ACL permission of group: Syntax : setfacl -x g:group: /path_to_file eg. setfacl -x g:admingrp: /devops

To remove all ACL permissions: Synatx: setfacl -b /path_to_file eg. setfacl -b /devops

To remove all entries

setfacl -b <target_file>

where,

-m - modification

-x - remove permission

-b - remove all entries

***********************************END**********************************