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 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 commands is
Let's take a simple example
Create a file from root user and set full permission on this file form chmod and verify it
now secure this file with +i options
create a new file again This time we will secure this file with +a options
To secure entire directory use –R switch. Directory secured with -R option can be reset only with –R switch.
Syntax for chattr commands is
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.
#chattr [operator] [switch] [file name]
-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
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 +i test
create a new file again This time we will secure this file with +a options
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 +a test
To secure entire directory use –R switch. Directory secured with -R option can be reset only with –R switch.
0 Comment:
Post a Comment