Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of Linux File Rights Management

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Guide in the Linux system, using permissions to protect the security of resources will be a good choice. The permissions of each file in the system have readable (r), writable (w) and executable (x) permissions, which correspond to permission values 4, 2, and 1, respectively. The system has default permissions for each file and directory, and each file can be divided into owners (u), users in the same group (g), and other groups of users (o). 1. Overview of file permissions

Permissions vary according to the type of file. Although each file has a permission of 777, when you create a file, you do not see that the permission of the file is 777. This is because some permissions are masked because of the mask.

For each file, it consists of different information, as shown in the figure. This is an empty file called CAT1 that we created earlier. The details of this file are shown below.

The difference between a text file and a catalog file is that the first descriptor is different, while the directory uses "d" as the descriptor. As shown in the figure, this is a directory called CAT that you created earlier, and the details and related descriptions of this directory are shown below.

Using the ls command with the-l option, you can identify the type of each file listed from the first letter of the license string. Here are several common identification numbers.

● -: general files (hard links).

● l: symbolic links (soft links, which can be created using the ln command with the-s option).

● d: directory.

● c: character device file.

● p: name the pipe.

● s: sockets.

● b: block device special files.

2. File rights management

From the CAT1 file you just created, you can see that although the file was created by the cat user, the cat user does not have executable permissions on the file. Now that you want to add executable rights (x) to CAT1, leave the task to the chmod command. Using the chmod command is also very simple, as shown below, to add executable rights to the CAT1 file for cat users.

[cat@cat] $chmod upright x CAT1

After the above operation, the cat user has the executable right to the CAT1 file. Of course, the same is true for adding other permissions, which can also be authorized using the "chmod+rwx file name". Interested readers can try, here only talk about the method, you can practice through this method, in order to better master.

If you also grant executable rights to directories under the CAT directory, you can use the Chmod command with the-R option in the following format:

Chmod-R directory name 1 / directory name 2

Where directory 2 is a subdirectory of directory 1, that is, directory 2 is created under directory 1.

Using the-R option, various permissions can be granted recursively.

Next, we will talk about revoking the permissions of a user (or user group) to the file, using the same command as chmod, as shown below, to revoke the executable rights of the cat user to the file CAT1.

[cat@cat] $chmod Umurx CAT1

According to the file permission value, 4 represents readable, 2 represents writable, and 1 represents executable, and if the permission value exists, it is expressed as 1, otherwise it is expressed as 0 (actually expressed in binary). You can calculate the permission value in a file or directory. As shown in the figure, the weight limit value named CAT1 file is calculated.

If you need to grant permissions to the file, you can also use the form of "chmod 664 CAT1" to authorize the user.

Sometimes, for convenience, you can use chown to change the owner of a file by granting ownership to someone else. Here's how to transfer the cat user's CAT1 file to the dog user and switch to the root user before execution. / home/CAT1 is used because the CAT1 file is in the home directory of the cat user.

[root@cat ~] # chown dog / home/cat/CAT1

After executing the command, you can use the ls command with the-l option to confirm that the change to the owner of the file was successful. The following command displays the details of the file after changing the owner of the file.

[cat@cat] $ls-ltotal 0 RW Aug-1 dog cat 0 Aug 9 21:27 CAT1

The original text is from: https://www.linuxprobe.com/linux-file-permession.html

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report