View and modify Linux file permissions

  1. Linux file permissions

The permissions of Linux files can be divided into four categories: readable, writable, executable, and no permissions. They are represented by characters r, w, x, - respectively.

2. Users and User Groups

Linux is a multi-user and multi-tasking operating system, which can better control file permissions through users and user groups .

Each file has an owner (a specific user), and the owner (user) belongs to a user group.

Therefore, the permissions of each file can be subdivided into:

  • owner permissions

  • User Group Other User Permissions

  • other user rights.

Different permissions can be set for the above three different types of users, so as to better manage permissions

3. File permission view

In the linux command line, enter: ls -la, you can view the permissions of all files under the current directory.

Among them, the permission item contains a total of 9 characters (the first - is not counted), and each group of three represents the owner, other users of the user group, and the permissions of other users. Take rw-r--r-- as an example:

The owner permission is: rw-, which means it has read and write permissions and no executable permissions.

Other user rights of the user group are: r--, which means only readable rights.

Other user permissions: r--, means only read permissions.

In addition, the first item is the file type, which is a common linux file type:

  • - Indicates that the file type is a normal file

  • d indicates that the file type is a directory file

  • l Indicates that the file type is a link file link file

  • p is the pipeline file pipe

  • s is the socket file socket

4. Modify file permissions

Modify the file permissions (if the permission is not enough when modifying the permissions, it is recommended to switch to the root user to operate.)

You can modify the permissions of the file through the command chmod. For convenience, the permissions are represented by numbers, and the numbers 4, 2, and 1 are used to represent read, write, and executable permissions. And it can be combined, such as 4 + 2 + 1 = 7, then 7 means read, write, and executable permissions, and 4 + 2 = 6 means read and write permissions. The specific commands are as follows:

chmod 764 file1
chmod 777 -R dir

There are three numbers in the command, which correspond to the owner, other users in the user group, and the permissions of other users.

764 indicates that the owner's permission is 7 (4 + 2 + 1, read and write and executable), other user permissions of the user group are 6 (4+2, read and write), and other user permissions are 4 (readable).

If you want to modify the permissions of a folder , you need to add -R, which means recursively modify the permissions of all files under the folder.

Guess you like

Origin blog.csdn.net/weixin_43354152/article/details/129068001