Administration FreeBSD Linux Tips and Tricks

Setting files as immutable.

Wouldn’t it be nice if we can set files so that even root cannot modify or delete it ? Both FreeBSD and Linux come with commands that allows us to set files as immutable.

If you have files that you don’t want anyone to modify/delete by mistake, then these commands are quite useful.

 

FreeBSD

In the case of FreeBSD, use the command chflags as below to set the file as immutable.

#chflags schg /root/test.txt

With immutable flags being set, even the root user won’t be allowed to delete/edit the file unless the flags are uncleared.
To clear the immutable flag, run the following command

#chflags noschg /root/test.txt

Linux

In the case of Linux, use the command chattr as below to set the immutable bit.

#chattr +i /root/test.txt

With immutable bit set, even the root user won’t be allowed to deleted/edit the file.

To clear the immutable flag, run the following command

#chattr -i /root/test.txt

 

Related Articles

  • A Basic Overview of the Vim Text Editor

    Many articles in our Webair Community advise editing configuration files. We usually recommend using your preferred text editor. I personally prefer vim. Vim, or its older sibling vi, are installed...
  • How to List Compiled PHP Modules from the Command Line

    The general command is php -m; this command will give you the full list of extensions: php -m This command will give you an output like: bz2 calendar Core ctype...
  • Disk Benchmarking Tools.

    One of the main bottlenecks in server slowness is the Disk IO. If the speed of your disks are slow, then the CPUs of your servers may be wasting their CPU...
  • Get CPU Information

    You can use the dmesg utility to display the contents of the system message buffer when FreeBSD comes up. For accuracy I recommend querying /var/run/dmesg.boot file. Usually a snapshot of...