MRKAVANA (mrkavana@gmail.com) - www.facebook.com/kavanathai

Aug 1, 2011

Secure special file with Linux chattr commands

In this part on file permission we will discuss about chattr commands. For exam prospective you should be aware about the basic function of chattr commands. chattr attribute is used to stop accidently deletation of files and folder. You cannot deletethe 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 commands 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.
-R
Recursively change attributes of directories and their contents. Symbolic links encountered during recursive directory traversals are ignored.
-a
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.
-i
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 commands 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 iswitch is in i you cannot append the file while in switch you can append the file.
chattr commands with a switchs
To secure entire directory use –R switch. Directory secured with -R option can be reset only with –R switch.
chattr commands with a switch



No comments:

Post a Comment