{"id":1120,"date":"2025-04-24T10:00:25","date_gmt":"2025-04-24T10:00:25","guid":{"rendered":"http:\/\/www.diveintoaccessibility.com\/?p=1120"},"modified":"2025-04-30T10:22:16","modified_gmt":"2025-04-30T10:22:16","slug":"how-to-make-files-immutable-in-linux-using-chattr-command","status":"publish","type":"post","link":"http:\/\/www.diveintoaccessibility.com\/index.php\/2025\/04\/24\/how-to-make-files-immutable-in-linux-using-chattr-command\/","title":{"rendered":"How to Make Files Immutable in Linux Using chattr Command"},"content":{"rendered":"

Have you ever accidentally deleted an important configuration file or overwritten changes you needed? Linux offers a powerful but lesser-known feature that can help prevent these situations: file immutability.<\/p>\n

Making a file immutable means it cannot be modified, deleted, renamed, or linked to-even by users with root privileges. This provides an extra layer of protection for critical system files or important data.<\/p>\n

In this guide, we\u2019ll look at how to use the chattr<\/code> command to make files immutable in Linux, what happens when you try to modify protected files, and how to remove this protection when needed.<\/p>\n


\n

Making Files Immutable in Linux<\/h2>\n

The chattr<\/code> (change attribute) command is what we\u2019ll use to make files immutable. Unlike regular file permissions that only restrict access based on user privileges, file attributes can prevent specific operations regardless of who attempts them.<\/p>\n

The Command Syntax<\/h3>\n

To make a file immutable, you use the chattr<\/code> command with the +i<\/code> flag:<\/p>\n

\r\nsudo chattr +i filename.txt\r\n<\/pre>\n

You\u2019ll need root privileges (using sudo<\/code>) to change file attributes, especially for system files. If you\u2019re not familiar with sudo<\/code>, check out our guide on how to use the sudo command in Linux<\/a>.<\/p>\n

What Happens When a File is Immutable?<\/h3>\n

Once a file is marked as immutable, several operations will fail with an \u201coperation not permitted\u201d error:<\/p>\n