Linux檔案特殊許可權和ACL-----CentOS 6.X

來源:互聯網
上載者:User

標籤:linux檔案特殊許可權及facl

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

umask

umask主要作用是定義使用者建立檔案或者目錄預設許可權

umask 預設值是0022一般情況下只看後四位因為第一位表示特殊許可權Sticky,suid,sgid。

使用者建立的目錄的預設許可權為 777,檔案的許可權為666這是因為目錄必須有一個X許可權位

[[email protected] ~]# umask 查看預設的umask

0022

[[email protected] ~]# mkdir test

[[email protected] ~]# ll -d test

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

[[email protected] ~]# touch txt

[[email protected] ~]# ll txt

-rw-r--r-- 1 root root 0 Sep 29 03:03 txt  檔案許可權666-022=644

自訂umask

[[email protected] tom]# umask 0033  這種修改方式只在當前shell有效

[[email protected] tom]# umask

0033

要想umask永久有效就必須將其寫入設定檔中

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

SUID

suid的許可權位在X位上,如果檔案當前有X許可權則是s否則便是S

suid的作用是使用者在執行該程式時,該進程的屬主不再是發起者本人,而是這個程式檔案的屬主

以/etc/shadow檔案為例

[[email protected] tmp]$ ll /etc/shadow

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

root使用者操作

[[email protected] tmp]# cp /bin/cat ./  避免破壞系統的cat所以將cat程式複製到目前的目錄下

[[email protected] tmp]# ll cat  查看修改前許可權

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

[[email protected] tmp]# chmod u+s cat  添加s許可權

[[email protected] tmp]# ll cat 

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

標準使用者

[[email protected] 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的方法

[[email protected] tmp]# chmod u-s cat

[[email protected] tmp]# ll cat

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

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

SUID SGID Sticky組成一組許可權位表示為

SUID 4

SGID 2

Sticky 1

[[email protected] tmp]# chmod 7644 cat

[[email protected] tmp]# ll cat

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

SGID和sticky許可權位一樣

SGID

屬組有s許可權,執行此程式時,其進程的屬組不再是運行者本人所屬的基本組,而是此程式檔案的屬組

 

[[email protected] tmp]# groupadd admin  添加一個測試組

[[email protected] tmp]# usermod -a -G admin job

[[email protected] tmp]# usermod -a -G admin tom  將這兩個使用者加入到admin組中 

[[email protected] tmp]# chown :admin test  改變目錄的所屬組 

[[email protected] tmp]# chmod g+ws test  添加GUID

 

[[email protected] tmp]# ll test/ -d  查看目錄許可權

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

 

[[email protected] test]$ touch tom  用tom使用者建立一個tom檔案

[[email protected] test]$ ll

total 0

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

[[email protected] 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

驗證

[[email protected] test]$ echo "tom" >job 將tom字元加入到job建立的檔案中無報錯

[[email protected] test]$ cat job 表示GUID生效檔案中有tom字元

tom 

[[email protected] test]$ rm -rf job  用tom使用者刪除job檔案

[[email protected] test]$ ll

total 0

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

Sticky

粘滯位,附加other的許可權上,表現為t

表現為一個公用檔案夾中的檔案,其他使用者可讀可寫但不能刪除其他人的檔案只有屬主才有許可權刪除

以上面的環境為基礎

[[email protected] tmp]# chmod o+t test/

[[email protected] tmp]# ll -d test/

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

[[email protected] test]$ echo "job" >tom 

[[email protected] test]$ cat tom

job 

[[email protected] test]$ rm -rf tom

rm: cannot remove `tom‘: Operation notpermitted 不能刪除其他使用者的檔案

ACL

存取控制清單添加單個使用者或組對某個檔案的操作許可權

setfacl

[[email protected] ~]$ ll

total 4

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

[[email protected] ~]$ setfacl -m u:tom:rw mic  設定某個使用者對該檔案有什麼許可權

getfacl

[[email protected] ~]$ getfacl mic/  查看該檔案的ACL

# file: mic/

# owner: job

# group: job

user::rwx

user:tom:rw-

group::---

mask::rw-

other::---

 

[[email protected] ~]$ setfacl -xu:tom mic  取消該使用者的所有許可權

[[email protected] ~]$ getfacl mic/

# file: mic/

# owner: job

# group: job

user::rwx

group::---

mask::---

other::---

 

[[email protected] ~]$ setfacl -mg:admin:rwx mic/ 設定組的ACL

[[email protected] ~]$ getfacl mic/

# file: mic/

# owner: job

# group: job

user::rwx

group::---

group:admin:rwx

mask::rwx

[[email protected] ~]$ setfacl -xg:admin mic  取消組的ACL

 

此文檔:http://down.51cto.com/data/1878394


本文出自 “LoveFish” 部落格,請務必保留此出處http://mictiger.blog.51cto.com/4854014/1559541

Linux檔案特殊許可權和ACL-----CentOS 6.X

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.