該權限針對二進制可執行文件,是普通用戶在執行該文件時臨時具備該文件全部者的權限windows
[root@test-01 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd [root@test-01 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@test-01 ~]# ls -l /usr/bin/ls -rwxr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls [root@test-01 ~]# chmod u+s /usr/bin/ls [root@test-01 ~]# !ls ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@test-01 ~]# su lichao [lichao@test-01 root]$ whoami lichao [lichao@test-01 root]$ ls ls: 沒法打開目錄.: 權限不夠 [lichao@test-01 root]$ ls 4 anaconda-ks.cfg
上面兩段代碼須要穿插着看,一開始沒有賦予/use/bin/ls set_uid權限時,普通用戶是沒法使用這個命令,而後經過執行chmod u+s /usr/bin/ls這條命令使普通用戶在執行ls時暫時擁有了root的權限,因此可以執行。ui
set gid 屬性能夠做用在二進制可執行文件上,也能夠做用在目錄上。看成用在可執行文件上時跟set uid 做用累死,它會使普通用戶在執行這個文件時具備文件所屬組的權限。目錄被設置這個屬性後,任何用戶在這個目錄下建立的文件都具備和該目錄所屬組相同的組。code
[root@test-01 tmp]# chmod g+s /tmp/1 [lichao@test-01 tmp]$ touch /tmp/1.txt [lichao@test-01 tmp]$ touch /tmp/1/2.txt [lichao@test-01 tmp]$ ls -l /tmp 總用量 4 drwxr-srwx. 3 root root 4096 12月 23 07:20 1 -rw-rw-r--. 1 lichao lichao 0 12月 23 07:17 1.txt -rw-------. 1 lc1 lc1 0 12月 12 17:07 yum.log [lichao@test-01 tmp]$ ls -l /tmp/1 總用量 4 drwxr-xr-x. 2 root root 6 12月 23 03:25 2 -rw-rw-r--. 1 lichao root 0 12月 23 07:20 2.txt [lichao@test-01 tmp]$
防刪除位,文件是否能被用戶刪除,主要看用戶對文件所在的目錄是否具備寫權限,若是沒有寫權限,就不能刪除該目錄下的文件,也不能添加新的文件,若是想讓用戶有添加新文件可是不能刪除別的用戶的文件,則須要改屬性,設置該屬性後,就算用戶對目錄具備寫權限,也不能刪除其餘用戶的文件it
[root@test-01 tmp]# chmod 777 /tmp/1 給一個目錄賦予777的權限 [root@test-01 tmp]# touch /tmp/1/123.t 在該目錄下建立一個空文件 [root@test-01 tmp]# su lichao 切換到普通用戶 [lichao@test-01 tmp]$ rm -f /tmp/1/123.t 使用普通用戶刪除該文件 [lichao@test-01 tmp]$ tree /tmp/1 成功刪除 /tmp/1 ├── 1.txt ├── 1_txt.swn ├── 1_txt.swo ├── 1_txt.swp ├── 2 └── 2.txt
[root@test-01 ~]# chmod o+t /tmp/1 給這個目錄添加sticky bit 屬性 [root@test-01 ~]# touch /tmp/1/123.t 使用root再次建立123.t空文件 [root@test-01 ~]# tree /tmp/1 查看建立結果 /tmp/1 ├── 123.t ├── 1.txt ├── 1_txt.swn ├── 1_txt.swo ├── 1_txt.swp ├── 2 └── 2.txt 1 directory, 6 files
[lichao@test-01 tmp]$ rm -f /tmp/1/123.t 使用普通用戶,再次刪除該目錄下的文件 rm: 沒法刪除"/tmp/1/123.t": 不容許的操做 沒法刪除 [lichao@test-01 tmp]$
軟連接 至關於windows裏面的快捷方式,它的命令是ln -s 源文件 快捷方式 與其餘命令不一樣的是執行這條命令,源文件放在前面test
[root@test-01 ~]# cp /etc/passwd /tmp/1 [root@test-01 ~]# tree /tmp /tmp ├── 1 │ ├── 123.t │ ├── 1.txt │ ├── 1_txt.swn │ ├── 1_txt.swo │ ├── 1_txt.swp │ ├── 2 │ ├── 2.txt │ └── passwd ├── 1.txt └── yum.log 2 directories, 9 files [root@test-01 ~]# ln -s /tmp/1/passwd /root/pawd [root@test-01 ~]# ls -l /root 總用量 4 drwxr-xr-x. 2 root root 6 12月 19 08:17 4 -rw-------. 1 root root 973 12月 12 17:09 anaconda-ks.cfg lrwxrwxrwx. 1 root root 13 12月 23 08:01 pawd -> /tmp/1/passwd [root@test-01 ~]#
ln -s 也能夠對目錄使用,就是說目錄也能夠作軟連接,可是一旦源文件丟失,軟連接就會提示錯誤。file
硬連接 硬連接不能做用在目錄上,也不能跨分區作硬連接,作完硬連接能夠刪除源文件,硬連接不受影響。硬連接至關於源文件的一層皮權限