標籤:sgid suid sticky
Linux中除了普通許可權之外,還有三個特殊許可權。
SUID::以檔案的所屬使用者執行,而非執行檔案的使用者,多用於可執行檔,設定suid後,在許可權位中,所屬使用者的 最後一個許可權為變為s,添加SUID許可權可用“+s”表示。
例如:passwd
[[email protected] ~]$ which passwd/usr/bin/passwd[[email protected] ~]$ ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 25980 Feb 22 2012 /usr/bin/passwd[[email protected] ~]$
SGID:主要針對檔案夾,在設定了SGID的檔案夾中建立任何新檔案都繼承該檔案的所屬組,設定sgid後,在許可權位中,所屬組的最後一個許可權位變為s,添加SGID許可權可用“+s”表示。
例如:
[[email protected] ~]$ mkdir ultraera[[email protected] ~]$ ls -ltotal 4drwxrwxr-x 2 adam adam 4096 Nov 27 21:09 ultraera[[email protected] ~]$ chmod g+s ultraera/[[email protected] ~]$ ls -ltotal 4drwxrwsr-x 2 adam adam 4096 Nov 27 21:09 ultraera[[email protected] ~]$ su Password: [[email protected] adam]# mkdir -p ultraera/test[[email protected] adam]# ls -l ultraera/total 4drwxr-sr-x 2 root adam 4096 Nov 27 21:09 test[[email protected] adam]#
sticky:針對檔案夾,對目錄擁有寫入權限的使用者,僅可以刪除其所擁有的檔案,無法刪除其他使用者所擁有的檔案,設定了sticky之後,在許可權位,other的最後一個許可權位變為t,添加SGID許可權可用“+t”表示。
例如:
[[email protected] tmp]# mkdir ultraera[[email protected] tmp]# chmod a=rwx,o+t ultraera/[[email protected] tmp]# ls -ld ultraera/drwxrwxrwt 2 root root 4096 Nov 27 21:29 ultraera/[[email protected] tmp]# useradd user1[[email protected] tmp]# useradd user2[[email protected] tmp]# su user1[[email protected] tmp]$ touch ./ultraera/test[[email protected] tmp]$ ls -l ultraera/total 0-rw-rw-r-- 1 user1 user1 0 Nov 27 21:31 test[[email protected] tmp]$ exitexit[[email protected] tmp]# su user2[[email protected] tmp]$ rm -f ./ultraera/test rm: cannot remove `./ultraera/test‘: Operation not permitted[[email protected] tmp]$
同樣使用chmod來設定特殊許可權,與普通許可權一樣,特殊許可權也可以用數字表示:
suid : 4
sgid : 2
sticky : 1
chmod 4644 filename #設定檔案suid許可權chmod 2755 flodername #設定檔案夾sgid許可權chmod 1755 flodername #設定檔案夾sticky許可權
本文出自 “南非部落” 部落格,請務必保留此出處http://ultraera.blog.51cto.com/6640392/1583493
Linux中的特殊許可權