Critical configuration files sometimes need a temporary guard that stops accidental edits during maintenance. The Linux immutable attribute blocks writes, renames, hard links, and deletes on the selected file until an administrator clears the flag.
The chattr command changes inode flags on supported Linux filesystems, and lsattr shows those flags. The immutable flag is separate from ownership, mode bits, and ACLs, so a file can look writable in ls -l while the kernel still refuses write access because the i attribute is present.
Setting or clearing the immutable flag requires root or the CAP_LINUX_IMMUTABLE capability. Not every filesystem supports every chattr flag, and already-open write file descriptors may keep writing after the flag is set, so close or restart writers before relying on the protection.
$ ls -l /srv/app/app.conf -rw-r--r-- 1 root root 14 Jun 13 09:30 /srv/app/app.conf
Apply the immutable flag only to the intended file. Services that need to update the file will fail until the flag is removed.
$ sudo lsattr /srv/app/app.conf --------------e------- /srv/app/app.conf
The i position is empty here, so the file is not immutable yet. The e flag is a normal ext4 extent flag and is not changed in this workflow.
$ sudo chattr +i /srv/app/app.conf
No output indicates chattr accepted the change. If it reports Operation not supported or Operation not permitted, confirm the filesystem supports the flag and that the command has the required privilege.
$ sudo lsattr /srv/app/app.conf ----i---------e------- /srv/app/app.conf
$ sudo sh -c 'printf "enabled=false\n" > /srv/app/app.conf' sh: 1: cannot create /srv/app/app.conf: Operation not permitted
The failure happens even with sudo because the immutable flag blocks opening the file for writing.
$ sudo rm /srv/app/app.conf rm: cannot remove '/srv/app/app.conf': Operation not permitted
A rename operation fails for the same reason; clear the flag before replacing, rotating, or deleting the file.
$ sudo chattr -i /srv/app/app.conf
$ sudo lsattr /srv/app/app.conf --------------e------- /srv/app/app.conf
$ sudo sh -c 'printf "enabled=false\n" > /srv/app/app.conf'
No output indicates the shell opened the file for writing and replaced the contents.
$ cat /srv/app/app.conf enabled=false