Managing File system security

In this article we will discuss about chattr command. For exam prospective you should be aware about the basic function of chattr command. chattr attribute is used to stop accidentally delete of files and folder. You cannot delete the files secured via chattr attribute even though you have full permission over files. This is very use full in system files like shadow and passwd files which contains all user information and passwords.

Syntax for chattr command is

 #chattr [operator] [switch] [file name] 

The operator ‘+’ causes the selected attributes to be added to the existing attributes of the files; ‘-’ causes them to be removed; and ‘=’ causes them to be the only attributes that the files have.


Recursively change attributes of directories and their contents. Symbolic links encountered during recursive directory traversals are ignored.


A file with the ‘a’ attribute set can only be open in append mode for writing. Only the superuser can set or clear this attribute.


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 can set or clear this attribute.

Let's take a simple example

Create a file from root user and set full permission on this file form chmod and verify it

#cat > test This test file
#chmod 777 test #ls –l 

cat linux commands

now secure this file with +i options

 #chattr +i test 

Now you can only read this file. All other actions excepts read will be denied including append, edit, rename or delete. chattr permission can be removed with –i options .

chattr command with i switchs

create a new file again This time we will secure this file with +a options

 #chattr +a test 

with a options you can read and append this file but all other recitations will be as it is. Main difference between a and i switch is in i you cannot append the file while in a switch you can append the file.

chattr command with a switchs

To secure entire directory use –R switch. Directory secured with -R option can be reset only with –R switch.

chattr command with a switch