Welcome 微信登录

首页 / 操作系统 / Linux / Linux系统运维技巧

我们有这样的需求:Linux系统下一个文件不允许别人修改、删除或者只允许添加,我们就可以使用chattr命令。[root@serv01 test]# cat note.txt
1.不许迟到
2.不许早退
3.不许抽烟
[root@serv01 test]# chattr +i note.txt#root用户都不能编辑
[root@serv01 test]# vim note.txt
[root@serv01 test]# cat note.txt
1.不许迟到
2.不许早退
3.不许抽烟#root用户不能删除 修改
[root@serv01 test]# rm -f note.txt
rm: cannot remove `note.txt": Operation not permitted
[root@serv01 test]# echo "this is test" >> note.txt
-bash: note.txt: Permission denied#ll查看文件属性不能看到,需要使用lsattr查看
[root@serv01 test]# ll note.txt
-rw-r--r--. 1 root root 45 Sep 21 17:46 note.txt
[root@serv01 test]# lsattr note.txt
----i--------e- note.txt#root用户不能修改只是个相对概念,root用户可以修改文件的属性,就可以修改了
[root@serv01 test]# chattr -i note.txt
[root@serv01 test]# lsattr note.txt
-------------e- note.txt
[root@serv01 test]# vim note.txt
[root@serv01 test]# cat note.txt
1.不许迟到
2.不许早退
3.不许抽烟
4.可以不来上班#留言板:自己说的话不能删除
[root@serv01 test]# vim note.txt
[root@serv01 test]# cat note.txt
1.不许迟到
2.不许早退
3.不许抽烟
4.可以不来上班
hello
[root@serv01 test]# chattr +a note.txt
[root@serv01 test]# lsattr note.txt
-----a-------e- note.txt
[root@serv01 test]# vim note.txt
[root@serv01 test]# ls
note.txt  note.txt~  note.txy~ note.txz~ 
#删除,发现没有权限
[root@serv01 test]# rm -rf *
rm: remove regular file `note.txt"? y
rm: cannot remove `note.txt": Operation not permitted
[root@serv01 test]# ls
note.txt  upload
[root@serv01 test]# echo "hello world" > note.txt
-bash: note.txt: Operation not permitted
#只能使用追加的方式添加内容
[root@serv01 test]# echo "hello world" >> note.txt
[root@serv01 test]# cat note.txt
1.不许迟到
2.不许早退
3.不许抽烟
4.可以不来上班
hello
hello world[root@serv01 test]# chattr -a note.txt
[root@serv01 test]# lsattr note.txt
-------------e- note.txt 
  • 1
  • 2
  • 下一页
【内容导航】
第1页:chattr和lsattr命令第2页:motd和issue文件
Linux播放器——RedHat下MPlayer和SMPlayer的安装RedHat Linux下QStarDict的安装相关资讯      Linux运维  chattr  lsattr  Linux系统运维 
  • Linux下不同运维人员共用root 账户  (今 17:10)
  • 在Linux中用chattr和lsattr命令管  (05/13/2015 14:25:13)
  • 如何成为一名优秀的Linux运维人员  (04/09/2015 16:44:45)
  • Linux运维入门到高级全套系列PDF  (08月01日)
  • Linux运维工程师面试-部分题库  (05/05/2015 19:29:15)
  • Linux主流架构运维工作简单剖析  (12/24/2014 07:53:13)
本文评论 查看全部评论 (0)
表情: 姓名: 字数