歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux 文件系統權限記序

Linux 文件系統權限記序

日期:2017/2/28 14:50:43   编辑:Linux教程

Linux 文件系統權限記序

用到程序:

chmod setfacl getfacl stat chattr lsattr
chmod:設置文件權限
setfacl:設置訪問控制列表(access control list)
getfacl:查看訪問控制列表
stat:顯示inode內容(a|m|c)time內容
chattr:設置第二擴展文件的列表文件屬性系統
lsattr:查看第二擴展文件的列表文件屬性系統
setuid:使文件擁有和文件屬主相同的x權限
setgid:使文件夾擁有和文件屬組相同的x權限
sticky:使文件不可冊除

Test:

  1. [root@nagios test]# touch setuid setgid sticky
  2. [root@nagios test]# chown -R nagios.nagios ./
  3. [root@nagios test]# chmod u+s setuid && chmod g+s setgid && chmod o+t sticky
  4. [root@nagios test]# ll
  5. total 0
  6. -rw-r-Sr-- 1 nagios nagios 0 Mar 2800:41 setgid
  7. -rwSr--r-- 1 nagios nagios 0 Mar 2800:41 setuid
  8. -rw-r--r-T 1 nagios nagios 0 Mar 2800:41 sticky
  9. [root@nagios test]# su hello
  10. [hello@nagios test]$ pwd
  11. /root/test
  12. [hello@nagios test]$ echo hello >> setuid
  13. bash: setuid: Permission denied
  14. [hello@nagios test]$ sh setuid
  15. hello
  16. [nagios@nagios test]$ exit
  17. exit
  18. [root@nagios test]# chmod o+w sticky
  19. [root@nagios test]# su hello
  20. [hello@nagios test]$ ll sticky
  21. -rw-rw-rwT 1 nagios nagios 0 Mar 2800:45 sticky
  22. [hello@nagios test]$ rm sticky
  23. rm: cannot remove `sticky': Permission denied
  24. [hello@nagios test]$ stat sticky
  25. File: `sticky'
  26. Size: 0 Blocks: 0 IO Block: 4096 regular empty file
  27. Device: fd00h/64768d Inode: 134198 Links: 1
  28. Access: (1666/-rw-rw-rwT) Uid: ( 500/ nagios) Gid: ( 500/ nagios)
  29. Access: 2013-03-2800:45:37.875928997 +0800
  30. Modify: 2013-03-2800:45:37.875928997 +0800
  31. Change: 2013-03-2800:46:28.050580800 +0800

#setfacl and getfacl

user:: user: 屬主權限 "::"均為屬主 ":" 為特殊用戶
group:: group: 組和特殊組
other:: 其它人
mask:: 除了屬主和其他人之外的所有人
常用選項:
-d : 子目錄繼承父目錄的特殊權限。
-R : 遞歸權限

查看是否支持ACL

  1. [root@nagios heelo]# tune2fs -l /dev/sda1 | grep option
  2. Default mount options: user_xattr acl

test:

  1. [root@nagios test]# touch setfacl
  2. [root@nagios test]# setfacl -m user::r,user:hello:rw setfacl
  3. [root@nagios test]# chown nagios.nagios setfacl
  4. [root@nagios test]# ll setfacl
  5. -r--rw-r--+ 1 nagios nagios 0 Mar 2800:52 setfacl
  6. [root@nagios test]# su nagios
  7. [nagios@nagios test]$ echo hello >> setfacl
  8. bash: setfacl: Permission denied
  9. [nagios@nagios test]$ exit
  10. exit
  11. [root@nagios test]# su hello
  12. [hello@nagios test]$ echo hello >> setfacl
  13. [hello@nagios test]$ cat setfacl
  14. hello
  15. [hello@nagios test]$ getfacl setfacl
  16. # file: setfacl
  17. # owner: nagios
  18. # group: nagios
  19. user::r--
  20. user:hello:rw-
  21. group::r--
  22. mask::rw-
  23. other::r--

#chattr and lsattr
Chattr +-=[acdeijstuADST].
A:Atime,告訴系統不要修改對這個文件的最後訪問時間。
S:Sync,一旦應用程序對這個文件執行了寫操作,使系統立刻把修改的結果寫到磁盤。
a:Append Only,系統只允許在這個文件之後追加數據,不允許任何進程覆蓋或截斷這個文件。如果目錄具有這個屬性,系統將只允許在這個目錄下建立和修改文件,而不允許刪除任何文件。
i:Immutable,系統不允許對這個文件進行任何的修改。如果目錄具有這個屬性,那麼任何的進程只能修改目錄之下的文件,不允許建立和刪除文件。
D:檢查壓縮文件中的錯誤。
d:No dump,在進行文件系統備份時,dump程序將忽略這個文件。
C:Compress,系統以透明的方式壓縮這個文件。從這個文件讀取時,返回的是解壓之後的數據;而向這個文件中寫入數據時,數據首先被壓縮之後才寫入磁盤。
s:Secure Delete,讓系統在刪除這個文件時,使用0填充文件所在的區域。
u:Undelete,當一個應用程序請求刪除這個文件,系統會保留其數據塊以便以後能夠恢復刪除這個文件。

test:

  1. [root@nagios test]# mkdir chattr
  2. [root@nagios test]# chattr +i chattr/
  3. [root@nagios test]# touch chattr/hello
  4. touch: cannot touch `chattr/hello': Permission denied
  5. [root@nagios test]# chattr -i +a chattr/
  6. [root@nagios test]# touch chattr/hello && echo hello >>chattr/hello && cat chattr/hello
  7. hello
  8. [root@nagios test]# rm chattr/hello
  9. rm: remove regular file `chattr/hello'? y
  10. rm: cannot remove `chattr/hello': Operation not permitted

《完》

Copyright © Linux教程網 All Rights Reserved