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

  • How to get rid of ^M characters.

    When you edit a file in Windows and then open in UNIX, you must have seen ^M characters getting appended in the content. How to get rid of it ?...
  • Identifying malicious mail scripts on FreeBSD

    This article will help you identify an possible spam scripts that may be causing unwanted outbound mail which could cause your servers ip address to be blacklisted.There are many different...
  • 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...
  • Reset MySQL Password

    Resetting a MySQL Root Password is one of the easiest things to do. However, finding documentation on how to do so can be challenging.   We as system administrators, have...