文件除了讀寫(r),寫(w),執行(x) 權限,還有些特殊權限(s,t)ide
功能:it
SUID權限僅對二進制程序有效class
執行者對於程序須要有X可執行的權限test
執行者將均有改程序全部者的權限file
本權限只在執行程序過程當中有效權限
舉例:二進制
普通用戶也能夠經過命令passwd修改本身的密碼。修改的密碼內容將會記錄/etc/shadow文件中,可是普通用戶對這個文件無任何權限,那如何修改這個文件呢?程序
以上步驟能夠理解爲這樣密碼
普通用戶執行passwd命令修改密碼èèpasswd命令程序修改/etc/shadow文件將密碼記錄其中方法
[root@localhost /]# ll /etc/shadow/usr/bin/passwd
-r-------- 1 root root 1352 02-14 10:36 /etc/shadow
-rwsr-xr-x 1 root root 23420 2010-08-11/usr/bin/passwd
這就是SUID的功能,當普通用戶在執行passwd程序命令時,因爲passwd具備SUID權限,同時普通用戶對於passwd命令具備X權限,那麼在passwd執行過程當中普通用戶將程序全部者(root)的權限,所以/etc/shadow就能夠被修改
SGID對於二進制程序來講,功能和SUID差很少
SGID權限對二進制程序有效
執行者對於程序須要有X可執行的權限
執行者將均有改程序用戶組的權限
本權限只在執行程序過程當中有效
SGID也能夠針對目錄設置,功能以下
用戶在具備SGID權限的目錄下建立的文件或目錄其所屬的用戶組就是目錄全部的有戶組
說明,默認狀況下用戶建立的文件所屬的用戶組爲用戶的有效用戶組
舉例
[root@localhost /]# mkdir -m 777 /tmp/newdir;ll -d /tmp/newdir drwxrwxrwx 2 root root 4096 03-10 12:35 /tmp/newdir [root@localhost /]# cd /tmp/newdir/ [root@localhost newdir]# touch rootfile [root@localhost newdir]# ll rootfile -rw-r--r-- 1 root root 0 03-10 12:35 rootfile =>所屬用戶和所屬用戶組都是root [root@localhost newdir]# su tkf =>切換到普通用戶 [tkf@localhost newdir]$ touch tkffile [tkf@localhost newdir]$ ll -rw-r--r-- 1 root root 0 03-10 12:35 rootfile -rw-rw-r-- 1 tkf tkf 0 03-10 12:36 tkffile =>所屬用戶和所屬用戶組都是tkf [root@localhost ~]# chmod g+s /tmp/newdir/ =>給newdir添加SGID權限 [root@localhost ~]# ll -d /tmp/newdir/ drwxrwsrwx 2 root root 4096 03-10 12:36 /tmp/newdir/ [root@localhost ~]# su tkf [tkf@localhost root]$ touch /tmp/newdir/sgidfile;ll /tmp/newdir/ -rw-r--r-- 1 root root 0 03-10 12:35 rootfile -rw-rw-r-- 1 tkf root 0 03-10 12:40 sgidfile -rw-rw-r-- 1 tkf tkf 0 03-10 12:36 tkffile => sgidfile文件所屬用戶組發生變化,和目錄(newdir)的用戶組同樣
SBIT只針對目錄有效,其主要功能是
當用戶擁有目錄的WX權限時,用戶能夠刪除(刪除,重命名,移動)目錄下的任意文件
當目錄擁有SBIT權限時,即便用戶擁有目錄的WX權限,用戶只能刪除本身建立的文件(能夠修改不是本身建立的文件)。root用戶均可以刪除
舉例
[root@localhost ~]# mkdir -m 1777 /tmp/bitdir [root@localhost ~]# su tkf [tkf@localhost root]$ ll -d /tmp/bitdir/ drwxrwxrwt 2 root root 4096 03-10 12:59 /tmp/bitdir/ =>tkf用戶擁有目錄的rwx權限 [tkf@localhost root]$ touch /tmp/bitdir/tkffile ;ll /tmp/bitdir/ -rw-rw-r-- 1 tkf tkf 0 03-10 12:59 tkffile =>在目錄下建立文件 [tkf@localhost root]$ su userA =>切換另外一個用戶 [userA@localhost root]$ ll -d /tmp/bitdir/ drwxrwxrwt 2 root root 4096 03-10 12:59 /tmp/bitdir/ => userA用戶擁有目錄的rwx權限 [userA@localhost root]$ cd /tmp/bitdir/ [userA@localhost bitdir]$ touch userfile;ll -rw-rw-r-- 1 tkf tkf 0 03-10 12:59 tkffile -rw-rw-r-- 1 userA userA 0 03-10 13:04 userfile =>在目錄下建立文件userfile [userA@localhost bitdir]$ rm tkffile rm:是否刪除有寫保護的 通常空文件 「tkffile」? y rm: 沒法刪除 「tkffile」: 不容許的操做 =>因爲目錄具備SBIT權限 雖然userA對目錄具備WX權限,可是不能刪除非他建立的文件 [root@localhost ~]# chmod o-t /tmp/bitdir/ =>將目錄SBIT權限去掉 [root@localhost ~]# su userA [userA@localhost root]$ cd /tmp/bitdir/ [userA@localhost bitdir]$ ll -rw-rw-r-- 1 tkf tkf 0 03-10 12:59 tkffile -rw-rw-r-- 1 userA userA 0 03-10 13:04 userfile [userA@localhost bitdir]$ rm tkffile rm:是否刪除有寫保護的 通常空文件 「tkffile」? y [userA@localhost bitdir]$ ll -rw-rw-r-- 1 userA userA 0 03-10 13:04 userfile =>能夠刪除不是本身建立的文件
和設置和基本權限(rwx)方法基本,能夠經過數字設置也能夠經過符號設置
SUID:4
SGID:2
SBIT:1
SUID:u+s
SGID:g+s
SBIT:o+t
舉例:
[root@localhost ~]# touch test [root@localhost ~]# chmod 4755 test; ll test -rwsr-xr-x 1 root root 0 03-10 13:14 test [root@localhost ~]# chmod 6755 test; ll test -rwsr-sr-x 1 root root 0 03-10 13:14 test [root@localhost ~]# chmod 1755 test; ll test -rwxr-xr-t 1 root root 0 03-10 13:14 test [root@localhost ~]# chmod 7666 test; ll test -rwSrwSrwT 1 root root 0 03-10 13:14 test =>這裏S,T都是大寫是由於文件自己不具備X權限,而S,T權限設置成功的 =>前提是文件具備X權限,所以大寫的ST表明文件無這些特殊權限