In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to set file permissions in the Linux system, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
1. Read-allows the group to read the file (represented by r)
two。 Write-allows the group to write files (represented by w)
3. Execute-allows the group to execute (run) files (represented by x)
To better explain how this applies to a grouping, for example, you allow a grouping to read and write a file, but cannot execute. Alternatively, you can allow a group to read and execute a file, but not write. Even you can allow a group to have full read, write, and execute permissions, or you can remove all permissions to remove the group's permissions.
Now, what is grouping? there are four:
1.user-the actual owner of the file
2.group-user group to which the user belongs
3.others-other users outside the user group
4.all-all users
In most cases, you will only operate on the first three groups, and the all group is only used as a shortcut (I'll explain later).
It's been easy so far, isn't it? Next we will take it to the next level.
If you open a terminal and run the command ls-l, you will see a line-by-line list of all files and folders in the current working directory (see figure).
You'll notice that the leftmost column is like-rw-rw-r--.
In fact, the list should look like this:
The code is as follows:
Rw- rw- rmuri-
As you can see, the list divides it into three parts:
1.rw-
2.rw-
3.r--
The order of permissions and groups is important, and the order is always:
1. Other members of the group to which they belong-grouping
two。 Read and write execution-permissions
In the permission list in our example above, the owner has read / write permission, the group has read / write permission, and other users only have read permission. If execution permission is given in these groups, it is represented by an x.
Equivalent value
Next, let's make it a little more complex, where each permission can be represented by a number. These figures are:
1. Read-4
two。 Write-2
3. Execute-1
Numerical substitution is not a replacement, you can't be like this:
The code is as follows:
-42-42-4Mui-
You should add up the values of each group and give users read and write permissions. You should use 4 + 2 to get 6. Give the user group the same permissions and use the same values. If you only want to give other users read permission, set it to 4. It is now expressed numerically as:
The code is as follows:
six hundred and sixty four
If you want to give a file 664 permissions, you can use the chmod command, such as:
The code is as follows:
Chmod 664 FILENAME
The file name is at FILENAME.
Change permissions
Now that you understand file permissions, it's time to learn how to change them. Is to use the chmod command to achieve. The first step is to know if you can change file permissions, you must be the owner of the file or have permission to edit the file (or get permission through su or sudo). Because of this, you can't change directories and change file permissions at will.
Continue to use our example (- rw-rw-r--). Suppose this file (named script.sh) is actually a shell script that needs to be executed, but you just want to give yourself permission to execute the script. At this point, you may think, "I need to be a file with permissions such as-rwx-rw-r--". To set the x permission bit, you can use the chmod command like this:
The code is as follows:
Chmod upright x script.sh
At this point, the list should show-rwx-rw-r--.
If you want both the user and the group to which he belongs to have execute permissions, the command should look like this:
The code is as follows:
Chmod ug+x script.sh
Do you understand how this works? Let's make it more interesting. Whatever the reason, you accidentally gave all groups permission to execute files (such as-rwx-rwx-r-x in the list).
If you want to remove execution rights from other users, just run the command:
[code]
Chmod Omurx script.sh
If you want to completely delete the executable permissions of a file, you can use two ways:
The code is as follows:
Chmod ugo-x script.sh
Or
The code is as follows:
Chmod Amurx script.sh
That's all it takes to make the operation more efficient. I want to avoid actions that may cause some problems (for example, you accidentally use the chmod command such as a-rwx on script.sh).
Directory permissions
You can also chmod a directory. When you create a new directory as a user, the new directory usually has the following permissions:
The code is as follows:
Drwxrwxr-x
Note: the beginning of d indicates that this is a directory.
As you can see, both the user and his group have permission to operate on the folder, but that doesn't mean that the files created in this folder have the same permissions (the files created use the default system permissions-rw-rw-r--). But if you want to create files in a new folder and remove write permissions from the user group, you don't have to change to that directory and use the chmod command for all files. You can use the chmod command with the parameter R (meaning recursion) to change the permissions of all files in the folder and its directory.
Now, suppose you have a folder TEST with some scripts, all of which (including the TEST folder) have permission-rwxrwxr-x. If you want to remove write permissions from the user group, you can run the command:
The code is as follows:
Chmod-R gmurw TEST
Run the command ls-l, and you will see that the permission information for the listed TEST folder is drwxr-xr-x. The user group is stripped of write permissions (as are all files in its directory).
This is the answer to the question about how to set file permissions in the Linux system. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.