Make a File Immutable with chattr +i

chattr sets filesystem attributes that override normal permissions — +i makes a file unmodifiable and undeletable, even by root.

LinuximmutablepermissionschattrMedium risk
Run `sudo chattr +i file` to lock a file, and `sudo chattr -i file` to unlock it.

01Command

Command
$ sudo chattr +i important.conf

02What it does

This is stronger than chmod 000: not even root can overwrite or remove an immutable file until the attribute is cleared, which is why it's used to pin critical configs — and why it mysteriously 'breaks' package updates when someone forgets they set it. Related flags: `+a` (append-only, great for logs that must never be edited) and `+u` (allow undelete recovery on some filesystems). Inspect current attributes with `lsattr file`.

03Risk

RiskMedium risk
Requirementsext2/3/4, xfs, btrfs filesystems; not supported on tmpfs or NFS
!Warning: If a file suddenly can't be deleted or a package upgrade fails with 'Operation not permitted' as root, check `lsattr` — an old +i flag is usually the cause.

04Undo

Undo
$ sudo chattr -i important.conf

05Sources

  • chattr(1) - Linux manual page
    man7.org · technical · 2026-09-17
    Evidence: The 'i' attribute makes a file immutable: it cannot be modified, deleted, renamed, or linked to, even by the superuser; use lsattr to view attributes.

Last verified: 2026-09-17 · Category: Files & Folders