20100301

create a file that root cant write it.

[1] If you change the permission of a file, not allow everyone to write.
But you will find that root can also write it, see below:
===============================================================================
# echo 1 > test
# chmod 444 test
# ls -l
-r--r--r-- 1 root root 2 2010-03-01 15:49 test
# echo 2 > test
# cat 2
2


[2] But you can use "chattr" to change the attrib of a file, not allow root to.
===============================================================================
# echo 1>1
# chattr +i 1
# echo 2>1
-bash: 1: Permission denied
# ls -l
total 4
-rw-r--r-- 1 root root 1 2010-03-01 16:12 1
# lsattr
----i------------- ./1


[3] We also find some directories of system are also set by "chattr".
===============================================================================
# lsattr /usr/
------------------ /usr/X11R6
--------------I--- /usr/bin
------------------ /usr/share
------------------ /usr/games
--------------I--- /usr/lib
------------------ /usr/src
------------------ /usr/sbin
------------------ /usr/include
------------------ /usr/local

[4] Reference:
===============================================================================
# man chattr
http://en.wikipedia.org/wiki/Chattr

没有评论:

发表评论