Linux文件特殊權限和ACL-----CentOS 6.X

ACL,Sticky,suid,sgid,umask的學習使用

umask

umask主要作用是定義用戶創建文件或者目錄默認權限

umask 默認值是0022一般情況下只看後四位因爲第一位表示特殊權限Sticky,suid,sgid。

用戶創建的目錄的默認權限爲 777,文件的權限爲666這是因爲目錄必須有一個X權限位

[root@www ~]# umask 查看默認的umask

0022

[root@www ~]# mkdir test

[root@www ~]# ll -d test

drwxr-xr-x 2 root root 4096 Sep 29 03:02test  test目錄權限爲777-022=755

[root@www ~]# touch txt

[root@www ~]# ll txt

-rw-r--r-- 1 root root 0 Sep 29 03:03 txt  文件權限666-022=644

自定義umask

[root@www tom]# umask 0033  這種修改方式只在當前shell有效

[root@www tom]# umask

0033

要想umask永久有效就必須將其寫入配置文件中

/etc/profile --> /etc/profile.d/*.sh--> ~/.bash_profile --> ~/.bashrc --> /etc/bashrc

SUID

suid的權限位在X位上,如果文件當前有X權限則是s否則便是S

suid的作用是用戶在執行該程序時,該進程的屬主不再是發起者本人,而是這個程序文件的屬主

/etc/shadow文件爲例

[tom@www tmp]$ ll /etc/shadow

---------- 1 root root 1628 Jun 15 16:50/etc/shadow

root用戶操作

[root@www tmp]# cp /bin/cat ./  避免破壞系統的cat所以將cat程序複製到當前目錄下

[root@www tmp]# ll cat  查看修改前權限

-rwxr-xr-x 1 root root 48568 Sep 29 03:35cat

[root@www tmp]# chmod u+s cat  添加s權限

[root@www tmp]# ll cat 

-rwsr-xr-x 1 root root 48568 Sep 29 03:35cat

標準用戶

[tom@www tmp]$ ./cat /etc/shadow

root:$6$Yw5E.CdTZgWaEn9/$LaEv1ZX2Rr1T2Ky21NdCeM0obRoE7baqBSqd2BcnHQC9CA2iF/wKqM6uFZTzeeUcpHzBPkwZRqdz3HhB9jZEI/:16146:0:99999:7:::

bin:*:15628:0:99999:7:::

daemon:*:15628:0:99999:7:::

adm:*:15628:0:99999:7:::

取消SUID的方法

[root@www tmp]# chmod u-s cat

[root@www tmp]# ll cat

-rwxr-xr-x 1 root root 48568 Sep 29 03:35cat

也可以用十進制數字添加或者刪除該權限位

SUID SGID Sticky組成一組權限位表示爲

SUID 4

SGID 2

Sticky 1

[root@www tmp]# chmod 7644 cat

[root@www tmp]# ll cat

-rwSr-Sr-T 1 root root 48568 Sep 29 03:35cat

SGIDsticky權限位一樣

SGID

屬組有s權限,執行此程序時,其進程的屬組不再是運行者本人所屬的基本組,而是此程序文件的屬組

 

[root@www tmp]# groupadd admin  添加一個測試組

[root@www tmp]# usermod -a -G admin job

[root@www tmp]# usermod -a -G admin tom  將這兩個用戶加入到admin組中 

[root@www tmp]# chown :admin test  改變目錄的所屬組 

[root@www tmp]# chmod g+ws test  添加GUID

 

[root@www tmp]# ll test/ -d  查看目錄權限

drwxr-sr-x 2root admin 4096 Sep 29 05:01 test/ 

 

[tom@www test]$ touch tom  tom用戶創建一個tom文件

[tom@www test]$ ll

total 0

-rw-rw-r-- 1 tom  admin 0 Sep 29 05:18 tom

[tom@www test]$ ll

total 4

-rw-rw-r-- 1 job admin 4 Sep 29 05:32 job

-rw-rw-r-- 1 tom admin 0 Sep 29 05:18 tom

驗證

[tom@www test]$ echo "tom" >job tom字符加入到job創建的文件中無報錯

[tom@www test]$ cat job 表示GUID生效文件中有tom字符

tom 

[tom@www test]$ rm -rf job  tom用戶刪除job文件

[tom@www test]$ ll

total 0

-rw-rw-r-- 1 tom admin 0 Sep 29 05:18 tom  

Sticky

粘滯位,附加other的權限上,表現爲t

表現爲一個公共文件夾中的文件,其他用戶可讀可寫但不能刪除其他人的文件只有屬主纔有權限刪除

以上面的環境爲基礎

[root@www tmp]# chmod o+t test/

[root@www tmp]# ll -d test/

drwxrwsr-t 2 root root 4096 Sep 29 06:05test/ 

[job@www test]$ echo "job" >tom 

[job@www test]$ cat tom

job 

[job@www test]$ rm -rf tom

rm: cannot remove `tom': Operation notpermitted 不能刪除其他用戶的文件

ACL

訪問控制列表添加單個用戶或組對某個文件的操作權限

setfacl

[job@www ~]$ ll

total 4

drwx------ 2 job job 4096 Sep 29 06:20 mic

[job@www ~]$ setfacl -m u:tom:rw mic  設置某個用戶對該文件有什麼權限

getfacl

[job@www ~]$ getfacl mic/  查看該文件的ACL

# file: mic/

# owner: job

# group: job

user::rwx

user:tom:rw-

group::---

mask::rw-

other::---

 

[job@www ~]$ setfacl -xu:tom mic  取消該用戶的所有權限

[job@www ~]$ getfacl mic/

# file: mic/

# owner: job

# group: job

user::rwx

group::---

mask::---

other::---

 

[job@www ~]$ setfacl -mg:admin:rwx mic/ 設置組的ACL

[job@www ~]$ getfacl mic/

# file: mic/

# owner: job

# group: job

user::rwx

group::---

group:admin:rwx

mask::rwx

[job@www ~]$ setfacl -xg:admin mic  取消組的ACL

 

此文檔下載地址:http://down.51cto.com/data/1878394


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章