I am trying to set an immutable attribute on some files that are in my home directory. But I keep getting:

chattr +i test.txt
chattr: Operation not permitted while setting flags on test.txt

but when I do:

sudo chattr +i test.txt

it works. Is this by design or am I doing something wrong? Internet guides are full of running the chattr without sudo.


1 Answer 1


From the chattr man page:

A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

The same applies to the a flag (append only), and the j flag (data journaling) requires the CAP_SYS_RESOURCE capability.

So getting an error when trying to se the i flag as a regular user is expected.

There are some other flags that don't require privileges to set, not that I'm sure there are too many useful ones. (E.g. the s (safe deletion) and u (undeletion) flags can be set by any user, they're just not honored by the filesystem...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .