l SUID 權限僅對二進制程序(binary program)有效;spa
l 本權限僅在執行該程序的過程當中有效 (run-time);視頻
l 執行者將具備該程序擁有者 (owner) 的權限。rem
[root@localhost tmp]# ll aaa 同步
-rw-r-----. 1 root root 10 Mar 13 21:42 aaait
[root@localhost tmp]# su - calfio
Last login: Fri Mar 13 21:26:08 CST 2020 on pts/0
[root@localhost ~]# ll /bin/cat
-rwxr-xr-x. 1 root root 54048 Jan 25 2014 /bin/cat
[root@localhost ~]# chmod 4755 /bin/cat
[root@localhost ~]# ll /bin/cat
-rwsr-xr-x. 1 root root 54048 Jan 25 2014 /bin/cat
[root@localhost tmp]# chmod u+s /bin/cat
Last login: Fri Mar 13 22:01:39 CST 2020 on pts/0
[root@localhost tmp]# chmod u-x /bin/cat
[root@localhost tmp]# ll /bin/cat
-rwSr-xr-x. 1 root root 54048 Jan 25 2014 /bin/cat
#注:1.S表示文件擁有者無x權限,s表示文件擁有者有x權限。
2.命令執行者必須具備x權限,不受文件擁有者是否有x權限的影響。
#注:效果和SUID同樣,只是SUID是得到擁有者的權限,而SGID是得到羣組的權限。
l 用戶若對於此目錄具備 r 與 x 的權限時,該用戶可以進入此目錄;
l 用戶在此目錄下的有效羣組(effective group)將會變成該目錄的羣組;
l 若用戶在此目錄下具備 w 的權限(能夠新建檔案),則使用者所創建的新檔案,該新檔案的羣組與此目錄的羣組相同。
[root@localhost tmp]# mkdir dir
[root@localhost tmp]# chmod 2777 dir
#設置SGID,同時開通滿權限
[root@localhost tmp]# ll -d dir/
drwxrwsrwx. 2 root root 17 Mar 13 22:20 dir/
[root@localhost tmp]# touch dir/root
#root帳號建立了文件root
[root@localhost tmp]# su - calf
Last login: Fri Mar 13 22:05:04 CST 2020 on pts/0
[calf@localhost ~]$ touch /tmp/dir/calf
#calf帳號建立了文件calf
-rw-rw-r--. 1 calf root 0 Mar 13 22:26 calf
-rw-r--r--. 1 root root 0 Mar 13 22:20 root
#注:不一樣用戶建立的文件都屬於root組,即父目錄dir所屬的組。
[root@localhost tmp]# chmod g-x dir/
[root@localhost tmp]# ll -d dir/
drwxrwSrwx. 2 root root 41 Mar 13 22:30 dir
2.文件的建立者必須對該目錄有w權限,與同組用戶是否具備w權限無關。
l 當用戶對於此目錄具備 w, x 權限,亦即具備寫入的權限時;
l 當用戶在該目錄下創建檔案或目錄時,僅有本身與 root 纔有權力刪除該檔案。
[root@localhost tmp]# mkdir dir
[root@localhost tmp]# chmod 1777 dir
[root@localhost tmp]# ll -d dir
drwxrwxrwt. 2 root root 6 Mar 13 22:47 dir
#注:只加SBIT的命令也能夠寫成:chmod o+t dir
[root@localhost tmp]# su - calf #切換到calf
Last login: Fri Mar 13 22:37:37 CST 2020 on pts/0
[calf@localhost ~]$ touch /tmp/dir/calf{1,2,3} #建立3個文件
[root@localhost tmp]# su - stu #切換到stu
Last login: Thu Mar 5 10:56:32 CST 2020 on pts/2
[stu@localhost ~]$ touch /tmp/dir/stu{1,2,3} #建立3個文件
-rw-rw-r--. 1 calf calf 0 Mar 13 22:50 calf1
-rw-rw-r--. 1 calf calf 0 Mar 13 22:50 calf2
-rw-rw-r--. 1 calf calf 0 Mar 13 22:50 calf3
-rw-rw-r--. 1 stu stu 0 Mar 13 22:51 stu1
-rw-rw-r--. 1 stu stu 0 Mar 13 22:51 stu2
-rw-rw-r--. 1 stu stu 0 Mar 13 22:51 stu3
[calf@localhost ~]$ cd /tmp/dir/
calf1 calf2 calf3 stu1 stu2 stu3
[calf@localhost dir]$ rm -f calf1 #測試刪除文件
calf2 calf3 stu1 stu2 stu3 #文件確實被刪除
[calf@localhost dir]$ rm -f stu1
rm: cannot remove ‘stu1’: Operation not permitted
#但不能刪除別人的文件
#注:用戶對目錄具備w權限,便可刪除該目錄下的文件。但此例中,用戶只能刪除擁有者是本身的文件,不能刪除擁有者是其餘用戶的文件。這就是SBIT的效果。
[root@localhost tmp]# chmod o-x dir/
[root@localhost tmp]# ll -d dir
drwxrwxrwT. 2 root root 63 Mar 13 22:54 dir
#注:1.T表示其餘用戶不具備x權限,t表示其餘用戶具備x權限。
2.操做者須要對目錄具備w權限。