Turn http://www.ha97.com/5172.html
PS: Sometimes you find that you cannot modify a file with root permissions, most of all because you have locked the file with the chattr command. The chattr command is very useful, some of which are supported by the Linux kernel version, but the majority of Linux systems running today are more than 2.6 cores. Modifying a property with the chattr command can improve the security of the system, but it is not suitable for all directories. The CHATTR command cannot protect/,/dev,/tmp,/var directories. The lsattr command is a file property that displays the Chattr command settings.
These two commands are used to view and change the file, directory properties, compared to chmod this command, chmod just change the file read and write, execute permissions, the more underlying property control is changed by Chattr.
Chattr Command usage: chattr [-RVF] [-v version] [mode] files ...
Most crucially in the [mode] section, the [mode] section is composed of +-= and [Asacddiijsttu] characters, which are used to control the file's
property.
+: Append parameters based on the original parameter setting.
-: Removes the parameter based on the original parameter setting.
=: Update to the specified parameter setting.
A: Atime (Access time) of a file or directory cannot be modified (modified), which can effectively prevent the occurrence of disk I/O errors such as laptops.
S: HDD I/O sync option, similar to sync.
A: Append, after setting this parameter, can only add data to the file, not delete, more for the server log file security, only root can set this property.
C: Compresse, sets whether the file is compressed and then stored. An automatic decompression operation is required for reading.
D: No dump, the settings file cannot be the backup target of the dump program.
I: The settings file cannot be deleted, renamed, linked, and cannot be written or added. The I parameter is useful for file system security settings.
J: Journal, which sets this parameter so that when the file system is mounted via the Mount parameter: data=ordered or Data=writeback, the file is recorded (in journal) when it is written. If the filesystem parameter is set to Data=journal, the parameter is automatically invalidated.
S: The file or directory is deleted confidentially, that is, the hard disk space is fully recovered.
U: In contrast to S, when set to U, the data content actually exists in the disk and can be used for undeletion. A and I are commonly used in the
parameter options. The A option enforces that only non-removable, multi-log system security settings can be added. While I is a more stringent security setting, only superuser (root) or processes with cap_linux_immutable processing power (identity) can apply this option.
Application Examples:
1. Use the chattr command to prevent a key file in the system from being modified:
# chattr +i /etc/resolv.conf
And then use mv/etc/resolv.conf and other commands to the file, are to get operation not permitted results. Vim will be prompted to W10:Warning:Changing a readonly file error when editing it. To modify this file, I will remove the I attribute: chattr-i/etc/resolv.conf
# lsattr/etc/resolv.conf
The following properties are displayed
----i-------- /etc/resolv.conf
2, let a file can only append data to the inside, but can not be deleted, applicable to various log files:
# chattr +a /var/log/messages
(GO) Linux chattr lsattr command