How to prevent a key file from being modified in Linux system
In a Linux environment, some important configuration files are not allowed to be modified by anyone, including root users. To prevent accidental deletion or modification, you may need to set the unmodifiable bit (immutable) permission for the file. Let's take the / etc/fstab file as an example, which records the important partition information of the hard disk, which is shown as follows:
[root@localhost ~] # cat / etc/fstab
#
/ etc/fstabCreated by anaconda on Sat Jun 8 16:22:16 2013
#
Accessible filesystems, by reference, are maintained under'/ dev/disk'See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info
#
UUID=3adeaadc-36c6-4b3b-bf99-aca7e6dfc15f / ext4 defaults 1 1
UUID=6a44e4ad-56b4-4877-8da4-e0bc21979b16 / boot ext4 defaults 1 2
UUID=e9ad5c94-6eee-4927-998a-9ce6024be355 / webserver ext4 defaults 1 2
UUID=5879d097-eadb-4ad2-bbb1-1b3323e86192 swap swap defaults 0 0
Tmpfs / dev/shm tmpfs defaults 0 0
Devpts / dev/pts devpts gid=5,mode=620 0 0
Sysfs / sys sysfs defaults 0 0
Proc / proc proc defaults 0 0
We use the chattr command for protection, which is as follows:
[root@localhost ~] # chattr + I / etc/fstab
If you need to modify the file, use the following command:
[root@localhost] # chattr-I / etc/fstab