In this tutorial we are talking about linux chattr command. The purpose of chattr attribute is to stop accidentally delete of file/folder. Even if you have full permission on particular file and files is secured with chattr command, so you cannot remove this particular file. This command is very useful for system administrator. We can apply on important files which contains all user infos and passwords like shadow and passwd files.
Syntax for linux chattr command is
chattr [operator] [switch] [file name]
attribute -i – file cannot be modified, renamed and deleted.
Implementation
Login to root user, create a file and set full permission on below mentioned file.
cat > attributed-file
This is my attributed test file.
chmod 777 attributed-file
ls -l attributed-file
-rwxrwxrwx 1 root root 28 May 17 01:25 attributed-file
Now apply +i option on following file.
chattr +i attributed-file
After implement on this file, all other actions will be denied only we can read this file. We can implement all actions on perticular file with –i option.
ls -l attributed-file
-rwxrwxrwx 1 root root 28 May 17 01:25 attributed-file
chattr +i attributed-file
lsattr attributed-file
----i--------e- attributed-file
cat attributed-file
This is my attributed test file.
cat >> attributed-file
-su: attributed-file: Permission denied
rm attributed-file
rm: cannot remove `attributed-file': Operation not permitted
mv attributed-file /home
mv: cannot move `attributed-file' to `/home/attributed-file': Operation not permitted
chattr -i attributed-file
lsattr attributed-file
-------------e- attributed-file
cat >> attributed-file
permission is removed.
rm attributed-file
Hope this tutorial will be helpful for you. Enjoy