#DevOps 6

Hello, everyone, this is my 6 blog. From this blog, I want to share my 6th-day experience OR some information on the File Permission And Access Control List

File Permissions and Access Control Lists

Lists of contents.

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

Each of the three permissions is assigned to three defined categories of users. The categories are:

  • owner — The owner of the file or application.

  • group — The group that owns the file or application.

  • "chgrp" is used to change the group permission of a file or directory.

  • others — All users with access to the system. (outside the users are in a group)

  • "chmod" is used to change the other user's permissions of a file or directory.

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

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

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

LETS START WITH SOME INTERESTING INFORMATION

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

Each of the three permissions is assigned to three defined categories of users. The categories are:

  • owner — The owner of the file or application.

  • group — The group that owns the file or application.

  • "chgrp" is used to change the group permission of a file or directory.

  • others — All users with access to the system. (outside the users are in a group)

  • "chmod" is used to change the other user's permissions of a file or directory.

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

ANS:-

I can walk you through the steps of making a basic file, granting various user categories access to it, and viewing its details with ls -ltr. Let's follow these steps:

  1. Make a Basic File:

You can use the touch or echo command to create a basic text file. This is how to apply touch:

touch my_file.txt

This command will create a file named my_file.txt in your current directory.

  1. Assign Owner, Group, and Other Permissions:

    To set permissions for the owner, group, and other users, use the chmod command. Three digits are used to represent permissions; an owner, group, and another category, along with the permissions associated with it, are represented by each digit.

    • Read permission is represented by 4.

    • 2 is the write-permission symbol.

    • Execute permission is represented by 1.

    • A zero indicates no authorization.

For every category, the permission digits are added together.

For instance, you can use the following to grant the owner read and write permissions and only read permissions to the group and others:

chmod 644 my_file.txt

This will set the permissions as follows:

  • Owner: read and write (6)

  • Group: read (4)

  • Others: read (4)

  1. View File Details using ls -ltr:

    After setting the permissions, you can use the ls -ltr command to view the file details. It will show the permissions, owner, group, and other information about the file.

ls -ltr my_file.txt

The output will look something like this:

-rw-r--r-- 1 your_username your_groupname 0 Oct 21 10:00 my_file.txt

Here's what the columns represent from left to right:

  • File permissions (e.g., -rw-r--r--)

  • Number of hard links

  • Owner's username

  • Owner's group

  • File size (in bytes)

  • Modification date and time

  • File/directory name

  1. Change User Permissions:

    If you want to change the permissions, you can use the chmod command again with the desired permission settings. For example, to give execute permission to the owner, you can use:

chmod 755 my_file.txt

This will set the permissions as follows:

  • Owner: read, write, and execute (7)

  • Group: read and execute (5)

  • Others: read and execute (5)

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

ANS:-

The rules that determine who can do what with a file or folder on a computer are called file permissions. They are crucial because they keep our belongings secure and well-organized. We'll explain file permissions in an understandable manner in this article.

  • Three Groups of Users:

    Consider your computer as a club, with each file and folder representing a member. These individuals fit into three groups:

    1. Owner: The person in charge of the file is akin to the club's boss. They have the most influence and can decide what happens to the file.

    2. Group: The group in the club is comparable to a group of friends. They are not as powerful as, but they do have certain special permissions.

    3. Others: Those outside the owner's group are just like everyone else. In the club, they are the least powerful.

  • Changing Permissions:

Let's now discuss how we can modify the permissions that each of these club members has when it comes to a file or folder.

We use a command called chgrp to modify a file or folder's group permission. It's similar to transferring your pals to a new club group.

We use a command called chmod to modify the permissions for others, or everyone else. It's similar to establishing guidelines for how guests may utilize the club's resources.

  • Understanding the Numbers:

To set these rules, we use numbers. Each number represents a type of permission:

1. 4 stands for read permission, which means you can see the contents of the file.

2. 2 stands for write permission, which means you can change the file.

3. 1 stands for execute permission, which means you can run a program or open a folder.

4. 0 means no permission at all.

  • These numbers are added up for each category (owner, group, others). For example, if we set permissions as 644, it means:

    1. The owner has read and write permissions (4+2 = 6).

    2. The group has read permission (4).

    3. Others have read permission (4).

  • Viewing File Details:

To see the permissions and other details of a file, we use a command called ls -ltr. It's like checking the club's rules for each member. The information includes:

  1. The permissions (like rw-r--r--) - It tells you what each category can do.

  2. The owner's username - It shows who's in charge of the file.

  3. The group's name - It tells you which group the file belongs to.

  4. File size - How big the file is in bytes.

  5. Modification date and time - When the file was last changed.

  6. File or folder name - Its name, of course.

  • Changing User Permissions:

If you want to change what the owner, group, or others can do with a file, you can use the chmod command again. For example, to give the owner the power to run a program, you can use chmod 755:

  1. The owner has read, write, and execute permissions (4+2+1 = 7).

  2. The group has read and execute permissions (4+1 = 5).

  3. Others have read and execute permissions (4+1 = 5).

Thus, while the owner can now use the file to run programs, other members of the club are still unable to do so.

These are the fundamentals of file permissions! It's similar to granting various club members unique abilities. Comprehending file permissions contributes to maintaining an orderly and secure digital environment.

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

ANS:-

In Unix-like operating systems, Access Control Lists (ACLs) are a way to set more precise permissions on files and directories. ACLs give you the ability to specify permissions for individual users or groups in addition to the standard permissions for the owner, group, and others. They provide more adaptability and control over the rights and permissions associated with a file or directory.

getfacl Input:

The command getfacl can be used to view a file or directory's ACL. Together with the default owner, group, and other permissions, it shows the ACL entries. Here's how to put it to use:

  • getfacl filename

To inspect a file or directory, replace "filename" with its name. You can view the ACL entries, along with the names of the users or groups and the corresponding permissions, by using the getfacl command

For example, if you run getfacl on a file named "my_file.txt," it might display something like:

  • file: my_file.txt

owner: your_username

group: your_groupname

user::rw- user:alice:rw- group::r-- mask::rw- other::r--

This output shows the ACL entries for the file, including the owner, a specific user "Alice," the group, and others.

setfacl Command:-

To set or alter a file or directory's ACL, use the setfacl command. With this command, you can add or remove particular permissions for users or groups. This is the fundamental syntax:

  • setfacl -m u:username: permissions filename

  • -m specifies that you're modifying the ACL.

  • u indicates that you're setting permissions for a user. Use g for a group.

  • username is the name of the user or group for which you want to set permissions.

  • permissions represents the desired permissions you want to assign.

For example, to grant read and write access to a user named "alice" for the file "my_file.txt," you would use:

  • setfacl -m u:alice:rw- my_file.txt

By adding an ACL entry, this command allows "Alice" to read and write to the file. Setfacl can also be used to add, remove, or alter ACL entries.

When you need to grant or restrict access for particular users or groups without modifying the standard owner, group, and others' permissions, using ACLs can be very useful. They offer greater access control flexibility.

Please be aware that your operating system and file system may have an impact on the availability and functionality of ACL commands. Before using these commands, confirm that your system supports ACLs. File Permission And Access Control List

THIS IS A SOME BASIC INFORMATION ABOUT File Permission And Access Control List.

THANK YOU FOR WATCHING THIS BLOG AND THE NEXT BLOG COMING SOON

Ritik Wankhede