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

  • Simple Stateful Load Balancer with iptables and NAT

    NOTE: To demonstrate how iptables can perform network address translation this how-to shows how to use it to implement a over-simplified load balancer. In practice we would use a daemon...
  • LAMP STACK

    What is a LAMP Stack? “LAMP stack is a popular open source web platform commonly used to run dynamic web sites and servers. It includes Linux, Apache, MySQL, and PHP/Python/Perl...
  • Scanning for rootkits and possible exploits – RKHunter

    Rootkits are malicious softwares that are installed by intruders to gain access to your server once the security of the server has been breached.  Intruders can leave some malicious softwares...
  • Assign range of IP addresses to an interface.

    Sometimes you may need to assign a wide range of IP addresses to your network interface in Linux systems. Instead of manually creating aliases for the network interface, it is...