Skip to main content

Command Palette

Search for a command to run...

#Devops Day6

Updated
•7 min read•View as Markdown

Hello, everyone, This is my Sixth blog started my day6 as AWS DevOps Engineer #90daysofchallenge with ShubhamLondhe #devops #trainwithshubham.

Tasks:-

File Permissions and Access Control Lists

1.File Permission

File permissions are a set of rules and settings that determine who can access, modify, or execute a file on a computer system. These permissions help control the security and privacy of files and directories in a file system. file permission are divided into three categories of users:

Owner (u):- Permission used for the owner of the file.

Group(g):-Permission used for the member of the group.

Other user(o):-Permission used by all other users.

2.Access Control Lists:-

An Access Control List (ACL) is a set of rules or configurations that define the permissions associated with an object, resource, or system. ACLs are commonly used in computer systems and networks to control access to files, directories, networks, or devices.

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

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

  • owner — The owner of the file or application.

  • "chown" is used to change the ownership permission of a file or directory.

  • 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. (outised the users are in a group)

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

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

    Ans:-You can use the touch command to create a basic text file.

  • touch my_file.txt

  • It 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.

      • 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:

      • Chmod644 my_file.txt

      • It 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 Jan 30 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

          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)

          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:

          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.

          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.

          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:

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

The group has read permission (4).

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:

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

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

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

File size - How big the file is in bytes.

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

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:

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

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

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 commandsgetfaclandsetfacl

    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.

More from this blog

LinuxBlog1

50 posts