set_uid:該權限針對二進制可執行文件,使文件在執行階段具備文件全部者的權限; 通俗一點講就是,普通用戶想要訪問一個沒有其餘用戶可執行權限的目錄時,暫時藉助二進制文件的所屬主權限去訪問這個目錄,若是沒有s權限,就不能訪問; 注意:普通用戶要有這個二進制文件的可執行權限。若是沒有,那也是不能訪問的。 咱們系統中passwd命令就具備s權限。當普通用戶執行passwd命令的時候,能夠臨時得到root權限,從而能夠更改密碼;node
系統修改密碼命令:passwdlinux
[root@linux-128 ~]# which passwd /usr/bin/passwd [root@linux-128 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd //顏色變成紅色
系統密碼文件:/etc/shadowui
[root@linux-128 ~]# ls -l /etc/shadow ---------- 1 root root 663 10月 20 15:14 /etc/shadow
注意:這裏全部者,所屬組,其餘用戶都沒有執行權限,可是root是超級用戶,它具備至高無上的權限,因此root用戶是能夠修改密碼的;按理說普通用戶沒有執行權限是沒辦法去修改密碼的,可是咱們passwd命令具備s權限,普通用戶在使用命令passwd時,能夠臨時獲取到passwd所屬主的root權限,因此能修改密碼。code
例子:使用普通用戶查看/root/目錄:rem
[root@linux-128 ~]# ls -ld /root/ //root目錄沒有其餘用戶可執行權限; dr-xr-x---. 3 root root 163 10月 25 00:45 /root/ [root@linux-128 ~]# su - wuzhou //切換用戶 上一次登陸:一 10月 23 21:56:30 CST 2017pts/0 上 [wuzhou@linux-128 ~]$ ls /root/ ls: 沒法打開目錄/root/: 權限不夠 //沒有權限
咱們怎樣才能讓普通用戶wuzhou打開/root/目錄呢? 解:咱們給ls命令加上一個s權限,讓用戶wuzhou臨時擁有ls的全部者權限;例如:it
[root@linux-128 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@linux-128 ~]# chmod u+s /usr/bin/ls [root@linux-128 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls [root@linux-128 ~]# su - wuzhou 上一次登陸:五 10月 27 00:18:52 CST 2017pts/0 上 [wuzhou@linux-128 ~]$ ls /root/ anaconda-ks.cfg
設置s權限:table
- chmod u+s 二進制文件名
- chmod u=rws 二進制文件名
- chmod 4755 二進制文件名 這個4是這樣得出來的:
suid = 4
sgid = 2
stick_bit = 1
取消s權限:test
- chmod u-s
- chmod u=rws
- chmod 755
set_gid:該權限能夠做用在二進制可執行文件上,也能夠做用在目錄上。看成用在文件上時,其功能和set_uid同樣,它會使文件在執行階段具備該文件所屬組的權限。做用在目錄上時,任務用戶在此目錄下建立的文件和目錄都具備和該目錄所屬組相同的組。登錄
設置s權限:file
- chmod g+s 二進制文件名或目錄
- chmod g=rws 二進制文件名或目錄
- chmod 2755 二進制文件名或目錄
例子:做用在二進制文件上
[root@linux ~]# ls -l /bin/ls -rwxr-xr-x. 1 root root 112664 10月 15 2014 /bin/ls [root@linux ~]# chmod g+s /bin/ls \\/bin/ls 加上sgid [root@linux ~]# !ls ls -l /bin/ls -rwxr-sr-x. 1 root root 112664 10月 15 2014 /bin/ls \\顏色會變成黃色 [root@linux ~]# su - wzzhan [wzzhan@linux ~]$ ls /root \\wzzhan用戶會調用命令ls屬組的權限去訪問/root目錄 111.bak 444 5.txt 777 install.log prem 222 4.txx 6.txt anaconda-ks.cfg install.log.syslog test
例子:做用於目錄上
[root@linux tmp]# mkdir 555 \\建立目錄555 [root@linux tmp]# chmod 777 555 \\設置權限全部人可讀可寫可執行 [root@linux tmp]# su - wzzhan \\切換用戶 wzzhan下 [wzzhan@linux ~]$ cd /tmp/555 [wzzhan@linux 555]$ mkdir dir \\建立目錄dir [wzzhan@linux 555]$ touch file \\建立文件file [wzzhan@linux 555]$ logout \\退出用戶到root下 [root@linux tmp]# chmod g+s 555 \\將目錄555添加sgid權限 [root@linux tmp]# su - wzzhan \\切換用到wzzhan下 [wzzhan@linux tmp]$ cd 555 [wzzhan@linux 555]$ mkdir dir1 \\建立目錄dir1 [wzzhan@linux 555]$ touch file1 \\建立文件file1 [wzzhan@linux 555]$ ls -l 總用量 8 drwxrwxr-x. 2 wzzhan wzzhan 4096 10月 27 15:04 dir drwxrwsr-x. 2 wzzhan root 4096 10月 27 15:06 dir1 \\建立的目錄的屬組是調用的目錄的屬組 -rw-rw-r--. 1 wzzhan wzzhan 0 10月 27 15:04 file -rw-rw-r--. 1 wzzhan root 0 10月 27 15:06 file1 \\建立的文件的屬組也是調用的目錄的屬組
sticky_bit:防刪除位。一個目錄下的文件嫩不能被刪除,不是取決於文件自己的屬組屬組還有其餘權限, 而是在於這個文件所在目錄的權限是否可讀可寫可執行,若是目錄可寫,那就意味着咱們能夠刪除目錄下的任何文件。當一個目錄的權限爲其餘人可讀可寫可執行的時候,那麼其餘用戶均可以刪除這個目錄下的文件,包括root文件,爲了防止文件被其餘用戶刪除,咱們給這這個目錄增長一種特殊權限:sticky,防刪除位,要用root用戶操做。這樣一個用戶就不能刪除另外一個用戶建立的文件了。只有root和建立文件本人才可以刪除。
設置t權限:
- chmod o+t 目錄
- chmod o=rwt 目錄
- chmod 1755 目錄
例子:
root@linux ~]# cd /tmp [root@linux tmp]# chmod o+t 666 [root@linux tmp]# ls -ld 666 drwxrwxrwt. 3 root root 4096 10月 27 15:42 666 [root@linux tmp]# su - user1 [user1@linux ~]$ cd /tmp/666 [user1@linux 666]$ ls -l 總用量 8 drwxrwxr-x. 2 wzzhan wzzhan 4096 10月 27 15:42 11 -rw-r--r--. 1 root root 337 10月 27 15:22 1.txt -rw-r--r--. 1 root root 0 10月 27 15:22 1.xt -rw-rw-r--. 1 wzzhan wzzhan 0 10月 27 15:42 2.txt [user1@linux 666]$ rm -r 111 rm: 沒法刪除"111": 沒有那個文件或目錄 [user1@linux 666]$ rm -r 11 rm:是否刪除有寫保護的目錄 "11"?y rm: 沒法刪除"11": 不容許的操做 [user1@linux 666]$ rm -r 1.txt rm:是否刪除有寫保護的普通文件 "1.txt"?y rm: 沒法刪除"1.txt": 不容許的操做 [user1@linux 666]$ rm -rf 2.txt rm: 沒法刪除"2.txt": 不容許的操做 [user1@linux 666]$ logout [root@linux tmp]# ls 1 22.txt 3 555 6.txt file1 test1 1.txt 2.txt 3.txt 666 dir1 test yum.log [root@linux tmp]# cd 666 [root@linux 666]# ls 11 1.txt 1.xt 2.txt [root@linux 666]# rm -rf 11 [root@linux 666]# ls 1.txt 1.xt 2.txt [root@linux 666]# su - wzzhan [wzzhan@linux ~]$ cd /tmp/666 [wzzhan@linux 666]$ ls -l 總用量 4 -rw-r--r--. 1 root root 337 10月 27 15:22 1.txt -rw-r--r--. 1 root root 0 10月 27 15:22 1.xt -rw-rw-r--. 1 wzzhan wzzhan 0 10月 27 15:42 2.txt [wzzhan@linux 666]$ rm 2.txt 用戶wzzhan才能刪除2。txt文件 [wzzhan@linux 666]$ ls -l 總用量 4 -rw-r--r--. 1 root root 337 10月 27 15:22 1.txt -rw-r--r--. 1 root root 0 10月 27 15:22 1.xt
軟連接:是創建一個獨立的文件,當讀取這個連接文件時,它會把讀取的行爲轉發到該文件所連接的文件上。
[root@linux-128 tmp]# ln -s /tmp/111/ /root/12 [root@linux-128 tmp]# ls -l /root 總用量 4 lrwxrwxrwx 1 root root 9 10月 27 01:12 12 -> /tmp/111/ -rw-------. 1 root root 1422 10月 17 03:51 anaconda-ks.cfg
比較源文件和軟連接的大小,軟鏈接的大小與源文件的長度有關
[root@linux-128 tmp]# du -sh /tmp/111/ /root/12 4.0K /tmp/111/ 0 /root/12
硬連接:當系統要讀取一個文件時,會先讀取inode信息,而後再根據inode的信息到塊區域將數據取出來。而硬連接就是直接在創建一個inode連接到文件放置的塊區域,即進行硬連接時,該文件的內容沒有任何變化,只是增長了一個指向這個文件的inode,並不會額外佔用磁盤空間。
[root@linux-128 tmp]# ln /tmp/123.txt /root/321.txt [root@linux-128 tmp]# ls -lih /tmp/123.txt 8389029 -rw-r--r-- 2 root root 17K 10月 27 01:31 /tmp/123.txt [root@linux-128 tmp]# ls -lih /root/321.txt 8389029 -rw-r--r-- 2 root root 17K 10月 27 01:31 /root/321.txt
注意:咱們建立的硬連接和源文件的inode同樣,大小同樣。
刪除源文件,硬連接不受影響 [root@linux-128 tmp]# rm /tmp/123.txt rm:是否刪除普通文件 "/tmp/123.txt"?y [root@linux-128 tmp]# ls -l /root/321.txt -rw-r--r-- 1 root root 16816 10月 27 01:31 /root/321.txt
硬連接不能連接目錄 [root@linux-128 tmp]# ln /tmp/222/ /root/23 ln: "/tmp/222/": 不容許將硬連接指向目錄