In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the "linux file permissions how to modify" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "linux file permissions how to modify" article can help you solve the problem.
"everything is a file" is one of the basic philosophies of Unix/Linux. Directories, character devices, block devices, sockets and so on all exist in the form of files in Unix/Linux. In the face of a large number of files, how to understand and manage their read, write and execute permissions?
Under Windows, you can view the permissions of a file in the property bar by right-clicking the file. Is the document "philosophy" under Linux the same as Windows? Let's analyze it from the following points.
1. The role of file permission settings
File permissions are set to protect the security of the system and user data. For users, the most important thing is the privacy and security of data and files. From system administrators to ordinary users, from file attributes to file special encryption, it all revolves around a theme: rights management. If a key file is written accidentally, the data will be lost or the system will crash.
Take the / proc directory file in the root directory as an example, which is a virtual file system provided by the linux kernel, which can access the internal data structure of the kernel and change the mechanism of kernel settings. Where swaps is the use of swap space, tty stores tty device information, version Linux kernel version and gcc version. We can find that these files that are closely associated with the system are all read-only, even for root users.
Figure 1 / partial files under proc
2. Division of file permissions
From the perspective of visitors, the rights management under Linux can be divided into three parts, namely, users, user groups and administrators. As shown in figure 2, open the details of the list of files in the current user directory. Most of the time we use this command only to focus on the right half of the information, such as file name, date, size, and so on. The left half shows the permission information of the corresponding file.
Figure 2 File attribute details
The Linux system has strict management on the rights of users. As shown in figure 3, the permissions of a file can be divided into three parts: permissions on the owner of the file, permissions on the user group of the owner, and permissions on other users. Among them, the user group (group) is a collection of users with the same characteristics.
Figure 3 File permissions
The information of users and user groups is in the passwd and group files in the / etc directory, respectively, and can be read directly using the cat command.
Figure 4 user / user group information
3. File permission change method
Linux provides the chmod command to change or set the permissions of the file. The command format is shown in figure 5, which removes the other user rights executable attributes from the hello file: vmuser@Linux-host: hello$ chmod Omurx hello. If u/g/o is set at the same time, a can be used to indicate, for example, to increase all user executable permissions for hello: vmuser@Linux-host: ~ $chmoda+x hello.
Figure 5 File permission change (1)
As we mentioned earlier, linux's file rights management is a "philosophical beauty", and the chmod command also provides a more indirect way to use it. As shown in figure 6, r, w and x correspond to the numbers 4, 2 and 1 respectively, and the sum of numbers is used to represent the set of permission values. For example, rwx can be represented by 7 and rmurx can be represented by 5. To set the hello file to the loosest permissions, you can directly use the command chmod 777 hello.
Figure 6 File permission change (2)
So in addition to creating files and then modifying permissions, can files with specific permissions be created directly? The answer is yes, we can manage the default permissions of the corresponding users by changing the value of umask. You can type umask directly to get the current user's permission default value, or you can use umask=xxx to modify it. In addition, if you want to set the value of umask permanently, you can modify ~ / .bashrc or. / bash_profile. The value of Umask does not correspond to the permissions of the file, and readers who are interested can consult the relevant materials.
Figure 7 user default permission change
4. How to protect important documents
The protection of files can start from the quantitative aspects: rights management of files, timely backup of files.
In terms of rights management, it is not optional to change file permissions, such as direct chmod 777 filename. Take the working log file of the system or APP as an example, it is only readable to most logged-in users, and if it is overwritten, the log information will be permanently lost. In the complex multi-user cooperative system, single user rights and group user rights should be strictly managed, and root user rights should be used cautiously.
Figure 8 read-only log file
This is the end of the content about "how to modify the permissions of linux files". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.