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

  • Patching The Ghost Vulnerability

    The Ghost vulnerability, also known as CVE-2015-0235, is an exploit in a library named glibc. This library is referenced by many applications which run on your server. The exploit is...
  • Prevent hot linking of images.

    Hot linking is displaying an image on a website by linking to the same image on another website, rather than saving a copy of it on the website on which...
  • How to Manage a Linux Server with systemd

    What Operating Systems Have Adopted systemd? CentOS: Yes, by default since CentOS 7 Fedora: Yes, since the release of Fedora 15 RedHat: Yes Debian: Yes, shipped since Debian 7 as...
  • 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 ?...