Decentralization in Linux

Tram Ho

Introduce

Linux is an open source operating system used by a lot of people. Many people have moved from Windows to Linux or vice versa, but when it comes to switching to a new operating system, it is difficult to become familiar with the new operating system. When moving from Windows to Linux, the file directory structure in Linux is completely different from Win, or you must be familiar with using commands to optimize work and especially the decentralization in Linux . This article I share about the decentralization in Linux, hope it will help you understand more about Linux and love it more.

The concept

There are two very important concepts to remember in Linux: permissions and ownership .

Ownership

Each file or directory on Linux is assigned by 3 types of owners: user , group , and other

User

By default on Linux, the person who created the file or directory becomes its own owner, just like when A person creates a B, the default person A will be the owner of the object. B there.

Group

A group can contain many users at the same time. All users in a group will have the same access to that file or folder. Suppose there is a learning material for a class that you do not want to let the other class know, just want to share in the class. Instead of giving you permission for each member in the class, you can group all the people in the class into a user group, and you assign permissions to a group of users so that only people in that group have access to the account. Whether.

Other

Other is any user who does not belong to the above 2 objects. Considering the above example, you are not in the class group that has access to the document, and you are not the owner of the document, you are considered other.

The problem is how to make Linux distinguish between these three types of users so that user A does not affect some files or directories containing information or data of a user B. And this is where permissions ( permission) is used to control the user’s image.

Permissions

Each file or directory in Linux has 3 read, write, execute rights defined for the 3 owners above.

  • Read : If it’s a file, this permission allows you to open it and read it. If it is a directory, it allows you to list the files or directories in that directory.
  • Write : Write permission allows you to modify the content of the file. If it is a directory, it allows you to add , delete and rename files in that directory.
  • Execute : With Windows you can run with a file ending in “.exe” easily. Unlike Windows, in Linux you cannot run it without permission. As for the directory, you can not access (cd) if you do not have permission to execute it.

Practice

See right

To list, view permissions and owner of files or directories:

The most general picture of rights in Linux:

It may look very confusing or confusing for those who are not familiar with Linux, but I will help you to understand each part.

On my Linux machine, I have created a file named file1 and a folder named dir1 , the default is, the creator will be the owner because the object I use hoavt account to create by default it has the owner user hoavt , So where are the team from? According to Linux, the user will be added to a group with the same name as that user because the user and group owner are hoavt . Let’s see what its rights will look like

With the first part I circled in red is the permissions I said above. It looks so awkward, isn’t it? Do not worry about the structure of the permissions will be divided into the following parts: first the file type, then the rights of each owner in the system will come.

file typeusergroupothername
drwxrxrxdir1
rw-r–r–file1

Look at the table you have divided into different columns. The first part in permissions will tell you whether it is in a file or a folder. Inside:

SymbolMeaning
dFolder
File

After distinguishing whether it is a file or a directory, go to the section of the rights you can do to each file or directory. It is divided into 3 parts: user , group , and other . Meaning of r, w, x :

SymbolMeaning
rRead
wWrite the
xEnforcement
No right

For users it is owned by hoavt and has the right to rwx with the directory dir1 means that I have the right to đọc, ghi, thực thi the directory dir1 when I am hoavt , and for file1 I only have the right to rw- , that is, I only have the right to read and write while executing, no rights should be marked with a sign. If you notice, the rights are written in rwx order just look over and see if the place is right or not, if it is replaced – (without the right) with the corresponding rights in that location.

The same for groups and other permissions is also arranged as user .

Change permissions with chmod

chmod stands for change mode to change the permissions of a directory or file on Linux.

Part rights by number

Permissions -number will basically have 3 digits a number with the meaning that the first number is the user right, the 2nd is the right of the group, the 3rd is the right of the other. The meaning of each digit here:

NumberSymbolMeaning
0No right
first–xEnforcement
2-w-Write the
3-wxExecute + Write
4r–Read
5rxRead + Execute
6rw-Read + Write
7rwxRead + Write + Execute

Suppose you need to delegate permission to a file named file1 rwxrw-r– rights. It means that the user has all read, write and execute rights. Group has read and write rights and other has read only. To do this we need to calculate the permissions for each owner.

user : r + w + x = 4 + 2 + 1 = 7

group : r + w = 4 + 2 = 6

other : r = 4 = 4

So the permissions of the whole file will be 764 , then use the following command to delegate:

You can also refer to the command

SymbolMeaning
uuser
ggroup
oother
aall

Change owner and group

You can also change the ownership of a file. To change it you need sudo .

To change a user:

To change a group:

To change both user and group:

summary

In a nutshell you need to remember a few main ideas as follows:

  • There are 3 types of owners of a file / directory on Linux: user, group, and other
  • Read, write and execute rights are signed with r, w and x corresponding to the numbers 4, 2 and 1.
  • Chmod command to change permissions, chown to change the owner user, chrgrp to change the group owner.

Refer

https://medium.com/@sajithnmadeesha/basics-of-linux-file-permission-5db00bd9749f

https://phoenixnap.com/kb/linux-file-permissions

https://www.guru99.com/file-permissions.html

Share the news now

Source : Viblo