How to prevent the modification of some important files in Linux
This article is to share with you about how to prevent the modification of some important documents in Linux, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
In the process of managing the Linux system, we often do not want users to modify some important key files, configuration files and important personal data at will. At this time, we need to protect the file from tampering with the file.
Permission protection is set to 600 permissions
For example:
[root@localhost /] # chmod 600 / usr/local/webserver/nginx/conf/nginx.conf
So we set the / usr/local/webserver/nginx/conf/nginx.conf file to 600 permissions to prevent modification.
Use the "chattr" command
Alternatively, if Linux is using an ext2, ext3, or ext4 file system, you can also use the "chattr" command:
The code is as follows:
Usage: chattr [- RVf] [- + = AacDdeijsSu] [- v version] files...
Use the I attribute
Add an I attribute to important files, and even root users cannot directly modify or delete such files to effectively prevent accidental modification or deletion of files. The specific commands are as follows:
The code is as follows:
# chattr + I passwd
Add an I attribute to the passwd file
Remove the I attribute using the following command:
The code is as follows:
# chattr-I passwd
Remove the attribute of the passwd file I and modify the file.
The above is how to prevent the modification of some important documents in Linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.