|
uid,gid,sticky bit的許可權概念
uid為4,gid為2,sticky bit為1,正好這三個可組成一個7
放在chmod原?砣粩滴磺耙晃患纯
例子:ls –l /bin/ping為
-rwsr-xr-x是不是怪怪的,紅色顯示哦
把-rwsr-xr-x分四部份
-為文件的?型,file 文件名可得到文件?型
rws為rwx加了一個uid如果rwS為rw-加一個uid
r-x如果加了gid,此處會為r-s即r-x加一個gid,如為r-S為r—加一個gid
r-x如果為r-t此處為r-x加了一個粘貼位,如果為r-T即為r-x加了粘貼位
uid的最大作用為
讓程式的執行者獲得用戶所擁有者的許可權
uid詳解
舉一例:
例如/bin/ping是一個只有root才能執行的程式,那麽普遍用戶要運行ping除了自己要有執行許可權,而且還要加root的許可權,才能運行…
所以這時uid就有作用了…
1.給了普遍用戶的x許可權還是ping不通哦因為icmp open socket只有root有許可權哦
[root@linux216 test]# chmod 711 /bin/ping
[root@linux216 test]# ls -l /bin/ping
-rwx—x--x 1 root root 30860 7月 29 2003 /bin/ping*
-bash-2.05b$ ping localhost
ping: icmp open socket: Operation not permitted
2.只給root關於rwx的許可權加uid即rws,但是不給普遍用戶的x的許可權,還是不能執行
[root@linux216 test]# chmod 4700 /bin/ping
[root@linux216 test]# ls -l /bin/ping
-rws------ 1 root root 30860 7月 29 2003 /bin/ping*
-bash-2.05b$ ping localhost
-bash: /bin/ping: Permission denied
3.給了root關於rwx的許可權加uid即rws.和給普遍用戶執行的許可權
就可以ping通了哦…………
[root@linux216 test]# chmod 4711 /bin/ping
[root@linux216 test]# ls -l /bin/ping
-rws--x--x 1 root root 30860 7月 29 2003 /bin/ping*
-bash-2.05b$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.078 ms
gid詳解
所有寫入有gid許可權目錄中的文件所屬主都與此目錄的所屬組一樣,有一點注意寫入的文件許可權?K不會與有gid的目錄許可權一樣…
舉一例:
[lfm@linux216 lfm]$ id
uid=8888(lfm) gid=100(users) groups=100(users)
[lfm@linux216 lfm]$ mkdir yandm
[lfm@linux216 lfm]$ ls -ld yandm/
drwxr-xr-x 2 lfm users 4096 9月 8 21:23 yandm//
[lfm@linux216 lfm]$ chmod g+s yandm/
[lfm@linux216 lfm]$ ls -ld yandm/
drwxr-sr-x 2 lfm users 4096 9月 8 21:23 yandm//
[root@linux216 yandm]# id
uid=0(root) gid=0(root) groups=0(root)
[root@linux216 yandm]# pwd
/home/lfm/yandm
[root@linux216 yandm]# touch hello
[root@linux216 yandm]# ls -l hello
-rw-r--r-- 1 root users 0 9月 8 21:26 hello
此處的hello文件的屬組?K不是root所在的root組哦,它為lfm所屬組users哦.但是許可權為文件的默認644哦
[root@linux216 yandm]# mkdir okok
[root@linux216 yandm]# ls -ld okok
drwxr-sr-x 2 root users 4096 9月 8 21:32 okok/
注意此處的ok文件屬組?K不是root所在的root組哦, 它為lfm所屬users組哦.而且為了lfm用戶目錄yandm/的gid繼續遞歸下去,也自動加上了gid哦…,但是許可權為目錄的默認許可權755哦.
Sticky bit詳解
加了sticky bit時別人刪除不掉,刪除的許可權只有屬主和自己,還有root.加了sticky bit和7的許可權,也不能刪,但是可以寫哦
1. 在lfm用戶下建立一個sb目錄,許可權為1777,在其中産生chain文件給777
許可權,另一個用戶pch對chain無刪除許可權,但是是可以寫入
[lfm@linux216 lfm]$ mkdir sb
[lfm@linux216 lfm]$ ls -ld sb
drwxr-xr-x 2 lfm users 4096 9月 8 21:47 sb/
[lfm@linux216 lfm]$ chmod 1777 sb/
[lfm@linux216 lfm]$ ls -ld sb
drwxrwxrwt 2 lfm users 4096 9月 8 21:47 sb/
[lfm@linux216 lfm]$ cd sb
[lfm@linux216 sb]$ pwd
/home/lfm/sb
[lfm@linux216 sb]$ touch chain
[lfm@linux216 sb]$ chmod 777 chain
[lfm@linux216 sb]$ ls -l chain
-rwxrwxrwx 1 lfm users 0 9月 8 21:48 chain*
[pch@linux216 pch]$ cd /home/lfm/sb
[pch@linux216 sb]$ ls -l
total 0
-rwxrwxrwx 1 lfm users 0 9月 8 21:48 chain*
[pch@linux216 sb]$ rm chain
rm: remove regular empty file `chain'? y
rm: cannot remove `chain': Operation not permitted
vi chain
"chain" 1L, 6C written
2.將目錄中粘貼位許可權拿掉,文件還是777時就可以刪除了..
[lfm@linux216 lfm]$ ls -ld sb
drwxrwxrwt 2 lfm users 4096 9月 8 21:54 sb/
[lfm@linux216 lfm]$ chmod 777 sb
[pch@linux216 lfm]$ pwd
/home/lfm
[pch@linux216 lfm]$ ls -ld sb
drwxrwxrwx 2 lfm users 4096 9月 8 21:54 sb/
[pch@linux216 lfm]$ cd sb
[pch@linux216 sb]$ ls
chain* chain~*
[pch@linux216 sb]$ rm ch
chain chain~
[pch@linux216 sb]$ rm chain
rm: remove regular file `chain'? y
[pch@linux216 sb]$ |
|