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

Linux的文件系統權限記序

日期:2017/3/3 15:59:39   编辑:關於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:

[root@nagios test]# touch setuid setgid sticky 
[root@nagios test]# chown -R nagios.nagios ./ 
[root@nagios test]# chmod u+s setuid && chmod g+s setgid && chmod o+t sticky 
[root@nagios test]# ll 
total 0
-rw-r-Sr-- 1 nagios nagios 0 Mar 28 00:41 setgid 
-rwSr--r-- 1 nagios nagios 0 Mar 28 00:41 setuid 
-rw-r--r-T 1 nagios nagios 0 Mar 28 00:41 sticky 
[root@nagios test]# su hello 
[hello@nagios test]$ pwd 
/root/test 
[hello@nagios test]$ echo hello >> setuid 
bash: setuid: Permission denied 
[hello@nagios test]$ sh setuid 
hello 
[nagios@nagios test]$ exit 
exit 
[root@nagios test]# chmod o+w sticky 
[root@nagios test]# su hello 
[hello@nagios test]$ ll sticky 
-rw-rw-rwT 1 nagios nagios 0 Mar 28 00:45 sticky 
[hello@nagios test]$ rm sticky 
rm: cannot remove `sticky': Permission denied 
[hello@nagios test]$ stat sticky 
  File: `sticky' 
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file 
Device: fd00h/64768d    Inode: 134198      Links: 1
Access: (1666/-rw-rw-rwT)  Uid: (  500/  nagios)   Gid: (  500/  nagios) 
Access: 2013-03-28 00:45:37.875928997 +0800
Modify: 2013-03-28 00:45:37.875928997 +0800
Change: 2013-03-28 00:46:28.050580800 +0800

#setfacl and getfacl

user:: user: 屬主權限 "::"均為屬主 ":" 為特殊用戶

group:: group: 組和特殊組

other:: 其它人

mask:: 除了屬主和其他人之外的所有人

常用選項:

-d : 子目錄繼承父目錄的特殊權限。

-R : 遞歸權限

查看是否支持ACL

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

test:

[root@nagios test]# touch setfacl 
[root@nagios test]# setfacl -m user::r,user:hello:rw setfacl 
[root@nagios test]# chown nagios.nagios setfacl 
[root@nagios test]# ll setfacl 
-r--rw-r--+ 1 nagios nagios 0 Mar 28 00:52 setfacl 
[root@nagios test]# su nagios 
[nagios@nagios test]$ echo hello >> setfacl 
bash: setfacl: Permission denied 
[nagios@nagios test]$ exit 
exit 
[root@nagios test]# su hello 
[hello@nagios test]$ echo hello >> setfacl 
[hello@nagios test]$ cat setfacl 
hello 
[hello@nagios test]$ getfacl setfacl 
# file: setfacl 
# owner: nagios 
# group: nagios 
user::r-- 
user:hello:rw- 
group::r-- 
mask::rw- 
other::r--

#chattr and lsattr

Chattr +-=[acdeijstuADST].

A:Atime,告訴系統不要修改對這個文件的最後訪問時間。

URL:http://www.bianceng.cn/OS/Linux/201410/45689.htm

S:Sync,一旦應用程序對這個文件執行了寫操作,使系統立刻把修改的結果寫到磁盤。

a:Append Only,系統只允許在這個文件之後追加數據,不允許任何進程覆蓋或截斷這個文件。如果目錄具有這個屬性,系統將只允許在這個目錄下建立和修改文件,而不允許刪除任何文件。

i:Immutable,系統不允許對這個文件進行任何的修改。如果目錄具有這個屬性,那麼任何的進程只能修改目錄之下的文件,不允許建立和刪除文件。

D:檢查壓縮文件中的錯誤。

d:No dump,在進行文件系統備份時,dump程序將忽略這個文件。

C:Compress,系統以透明的方式壓縮這個文件。從這個文件讀取時,返回的是解壓之後的數據;而向這個文件中寫入數據時,數據首先被壓縮之後才寫入磁盤。

s:Secure Delete,讓系統在刪除這個文件時,使用0填充文件所在的區域。

u:Undelete,當一個應用程序請求刪除這個文件,系統會保留其數據塊以便以後能夠恢復刪除這個文件。

test:

[root@nagios test]# mkdir chattr 
[root@nagios test]# chattr +i chattr/ 
[root@nagios test]# touch chattr/hello 
touch: cannot touch `chattr/hello': Permission denied 
[root@nagios test]# chattr -i +a chattr/ 
[root@nagios test]# touch chattr/hello && echo hello >>chattr/hello && cat chattr/hello 
hello 
[root@nagios test]# rm chattr/hello 
rm: remove regular file `chattr/hello'? y 
rm: cannot remove `chattr/hello': Operation not permitted
Copyright © Linux教程網 All Rights Reserved