linux系統中的許可權管理(下)
六.特殊許可權
#stickyid 粘制位
#針對目錄: #如果一個目錄stickyid開啟,那麼這個目錄中的檔案
#只能被檔案所有人刪除
chmod 1原始許可權 dir
chmod o+t dir
實驗:
mkdir /mnt/guo
chmod 777 /mnt/guo
su - westos ----> touch /mnt/guo/111
su - kiosk ---->
rm -fr /mnt/guo/111 #可以刪除
rm -fr /mnt/guo/111 #不屬於自己的檔案也可以刪除
chmod 1777 /mnt/guo
chmod o+t /mnt/guo
以上兩條命令都可以開啟mnt/guo目錄的t許可權
su - westos ----> touch /mnt/guo
exit
su - kiosk -------->
rm -fr /pub/leefile #可以刪除
rm -fr /pub/westosfile #不屬於自己的檔案不能刪除
rm: cannot remove ‘westosfile’: Operation not permitted
#sgid 強制位
#針對目錄: 目錄中新建的檔案自動歸屬到目錄的所屬組中
設定:
chmod 2原始檔許可權 dir
chmod g+s dir
實驗
group westos
mkdir /mnt/guo
chmod 777 /mnt/guo
chgrp westos.westos /mnt/guo/
root —> touch /mnt/guo##是誰建立的檔案組就是誰的
chmod g+s /mnt/guo
root —> touch /mnt/guo/111 ##111自動複製了/mnt/guo目錄組
#只針對二進位制的可執行檔案(c程式)
#當執行二進位制可執行檔案時都是用檔案擁有組身份執行,和執行使用者無關
實驗:
su - westos
/bin/watch cat
ps ax -o user,group,comm | grep watch
westos westos cat
用root使用者身份
chmod g+s /bin/watch
su - westos
ps ax -o user,group,comm | grep watch
westos root cat
#suid 冒險位
#只針對二進位制的可執行檔案(c程式)
#當執行二進位制可執行檔案時都是用檔案擁有者身份執行,和執行使用者無關
chmod 4原屬性 file
chmod u+s file
實驗:
su - westos
/bin/cat
ps ax -o user,group,comm | grep watch
westos westos watch
用root使用者身份
chmod u+s /bin/cat
su - westos
/bin/cat
ps ax -o user,group,comm | grep watch
root westos watch
七.acl許可權列表
Aiccess Control Lists #訪問控制列表
#功能:
#在列表中可以設定特殊使用者對與特殊檔案有特殊許可權
#acl列表開啟標識
-rw-rw---- 1 root root 0 Apr 18 09:03 /mnt/guo
^
沒有"+"代表acl列表未開啟
-rw-rw----+ 1 root root 0 Apr 18 09:03 /mnt/guo
^
acl列表功能開啟
#acl列表許可權讀取
getfacl +檔名
顯示內容分析
#file: westosfile #檔名稱
#owner: root #檔案擁有者
#group: root #檔案擁有組
user::rw- #檔案擁有者許可權
user:lee:rw- #特殊指定使用者許可權
group::r-- #檔案擁有組許可權
group:westos:— #特殊指定的使用者組的許可權
mask::rw- #能夠賦予特殊使用者和特殊使用者組的最大許可權閥值
other::r-- #其他人的許可權
“注意:”
“當檔案許可權列表開啟,不要用ls -l 的方式來讀取檔案的許可權”
#acl列表的控制
setfacl -m u:westos:rwx /mnt/guo #設定
setfacl -m g:westos:rwx /mnt/guo
setfacl -m u::rwx /mnt/guo
setfacl -m g::0 /mnt/guo
setfacl -x u:westos /mnt/guo##刪除列表中的westos
setfacl -b /mnt/guo #關閉
#acl 許可權優先順序
擁有者 > 特殊指定使用者 > 許可權多的組 >許可權少的組 > 其他
設定擁有者和特殊擁有者同一個,給特殊的滿許可權,擁有者0許可權,切換到該使用者在/mnt/guo/目錄下建立檔案,成功說明特殊的優先級別高,反之擁有者優先順序高
#acl mask 控制
#mask是能夠賦予指定使用者許可權的最大閥值
問題
當設定完畢檔案的acl列表之後用chmod縮小了檔案擁有組的權力
mask會發生變化
恢復:
setfacl -m m:許可權 檔案
#acl 列表的預設許可權
setfacl -m u:lee:rwx /mnt/westosdir ##只對於/mnt/westosdir目錄本身生效
setfacl -Rm u:lee:rwx /mnt/westosdir ##對於/mnt/westosdir目錄和目錄中已經存在的內容生效
#以上的命令之針對與存在的檔案生效,新建檔案是不會被設定的
setfacl -m d:u:lee:rwx /mnt/westosdir/ ##針對與/mnt/westosdir目錄中新建檔案生效
#八.attr許可權
#attr許可權限制所有使用者
i #不能作任何的更改
a #能新增不能刪除
lsattr dir|file ##檢視attr許可權
chattr +i|+a|-i|-a dir|file ##設定attr許可權