Home >Operation and Maintenance >Linux Operation and Maintenance >How to set linux not to allow permission changes

How to set linux not to allow permission changes

WBOY
WBOYOriginal
2022-05-23 16:28:554850browse

In Linux, you can use the chattr command to set permissions that are not allowed to be changed. This command is used to change file attributes. When the attribute is set to "i", it means that the file or directory must not be changed arbitrarily, that is, it is set Changing permissions is not allowed, the syntax is "chattr u i file or directory".

How to set linux not to allow permission changes

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to set Linux to not allow permission changes

Linux chattr command is used to change file attributes.

This command can change the attributes of files or directories stored on the ext2 file system. These attributes have the following 8 modes:

a: Make the file or directory only for additional purposes.

b: Do not update the last access time of the file or directory.

c: Compress the file or directory and store it.

d: Exclude files or directories from dumping operations.

i: Files or directories are not allowed to be changed arbitrarily.

s: Confidentially delete files or directories.

S: Update files or directories instantly.

u: Prevent accidental deletion.

Syntax

chattr [-RV][-v<版本编号>][+/-/=<属性>][文件或目录...]

Parameters

 -R Recursive processing, processing all files and subdirectories in the specified directory together.

 -v Set the file or directory version.

 -V displays the instruction execution process.

  Turn on this attribute of the file or directory.

 - Turn off the attribute of the file or directory.

 = Specify the attribute of the file or directory.

Examples are as follows:

i: Permissions cannot be modified

Example: chattr u i filename (corresponding folder), then the filename file cannot be modified by anyone, no matter who , if you need to modify it, you need to delete the i permission first, just use chattr -i filename. Check whether the i permission is set on the file using lsattr filename.

First, we use xshell to see if we have i permission. lsattr filename. as the picture shows.

How to set linux not to allow permission changes

Next, remove the i permission and enter in xshell, chattr -i filename. as the picture shows.

How to set linux not to allow permission changes

At this time, there is no prompt, but the modification has been successful. Then I went to xftp to modify the permissions and found that it was easy. Usually, in order to prevent files or websites from being invaded by others, we can also add i permissions. Enter in xshell, chattr i filename. as the picture shows. There is also no prompt, but it has been successful.

How to set linux not to allow permission changes

Recommended learning: Linux video tutorial

The above is the detailed content of How to set linux not to allow permission changes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn