Detailed explanation of chattr and lsattr commands of Centos

Source: Internet
Author: User
PS: sometimes you find that you cannot modify a file with the root permission, most of the reason is that you used the chattr command to lock the file. The chattr command has a great role. some of the functions are supported by the linux kernel version. However, most of the linux systems that run in production are now over 2.6 kernels. Modifying attributes using the chattr command can improve system security, but it is not suitable for all directories. The chattr command cannot protect the/,/dev,/tmp, and/var directories. The lsattr command is to display

PS: sometimes you find that you cannot modify a file with the root permission, most of the reason is that you used the chattr command to lock the file. The chattr command has a great role. some of the functions are supported by the linux kernel version. However, most of the linux systems that run in production are now over 2.6 kernels. Modifying attributes using the chattr command can improve system security, but it is not suitable for all directories. The chattr command cannot protect the/,/dev,/tmp, and/var directories. The lsattr command displays the file attributes set by the chattr command.

These two commands are used to view and change the file and directory attributes. compared with the chmod command, chmod only changes the read/write and execute permissions of the file, the underlying property control is changed by chattr.

Usage of the chattr command: chattr [-RVf] [-v version] [mode] files...
The most important part is in the [mode] section. the [mode] section is composed of the +-= and [ASacDdIijsTtu] characters, which are used to control files.
Attribute.

+: Append parameters based on the original parameter settings.
-: Remove the parameter based on the original parameter settings.
=: Updated to the specified parameter settings.
A: The atime (access time) of A file or directory cannot be modified, which can effectively prevent I/O errors on A laptop disk.
S: Hard disk I/O synchronization option, similar to sync.
A: append. after this parameter is set, data can only be added to the file, but cannot be deleted. This attribute is mostly used for server log file security and can only be set by root.
C: compresse: specifies whether the file is compressed before being stored. Automatic decompression is required for reading.
D: no dump. the file cannot be the backup target of the dump program.
I: The set file cannot be deleted, renamed, or linked, and cannot be written or added. The I parameter is very helpful for security settings of the file system.
J: That is, journal. this parameter is set so that when the file system is mounted by the mount parameter: data = ordered or data = writeback, the file is first recorded (in journal) when written ). If the filesystem parameter is set to data = journal, this parameter is automatically invalid.
S: Confidential deletion of files or directories, that is, the hard disk space is all withdrawn.
U: opposite to s. when set to u, the data content still exists in the disk and can be used for undeletion.
A and I are often used in each parameter option. Option a can only be added and cannot be deleted. it is mostly used for security settings of the log system. I is a more rigorous security setting. this option can be applied only to processes with superuser (root) or CAP_LINUX_IMMUTABLE processing capability (identifier.

Example:

1. use the chattr command to prevent the modification of a key file in the system:
# chattr +i /etc/resolv.conf

Then run mv/etc/resolv. conf and other commands to operate on the file. Operation not permitted is obtained. When editing the file, vim prompts the W10: Warning: Changing a readonly file error. To modify this file, remove the I attribute: chattr-I/etc/resolv. conf.

# Lsattr/etc/resolv. conf
The following attributes are displayed:
----i-------- /etc/resolv.conf

2. allow a file to only append data to it, but not delete it. it is applicable to various log files:
# chattr +a /var/log/messages


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.