linux[基礎]-20-用戶與文件權限-[文件特殊權限]-[01]
用戶與文件權限
用戶:
用戶root是系統的超級管理員,而真正讓他成為管理員的不是
用戶名“root”,而是其UID編號。
UID:每個用戶都有相對應的UID號,就像我們的身份證號一樣
超級用戶:UID為0也就是root用戶
系統用戶:UID 1~999 系統服務的用戶,默認被限制登錄系統
普通用戶:UID 1000~ 管理員創建的用戶不能管理系統的用戶
帳戶名稱與UID存放在/etc/passwd文件
密碼存放在/etc/shadow文件
GID:用戶組的編號,方便授權指派工作
每個用戶的創建都會默認創建一個以用戶名為名的用戶組
其GID與UID相同,稱“基本組”
而加入的組叫做“擴展組”
用戶組與GID存放在/etc/group文件中
文件權限:
文件類型:
[[email protected] etc]# ll
總用量 1412
drwxr-xr-x. 3 root root 97 11月 24 2015 abrt
-rw-r--r--. 1 root root 16 11月 24 2015 adjtime
開頭字符代表文件類型:
-:文件
d:目錄
l:鏈接文件
b:塊設備文件
c:字符設備文件
p:管道文件
SGID:
功能1:讓使用者臨時擁有屬組的權限
如: ps命令
[[email protected] tmp]$ ll /bin/ps
-rwxr-xr-x. 1 root root 100120 Feb 27 2014 /bin/ps
[[email protected] tmp]$ ps
PID TTY TIME CMD
3795 pts/0 00:00:00 bash
3902 pts/0 00:00:00 bash
4312 pts/0 00:00:00 bash
4349 pts/0 00:00:00 ps
功能2:在此目錄創建的文件自動繼承該目錄的屬組(只可以對目錄設置)
如:比如一個部門的文件,設置以後,會方便管理
Chmod : 用於修改文件或目錄的權限 :chmod [參數] 文件/目錄
Chown :用於設置文件或者目錄的屬主/組 :chown [參數] 屬主:屬組 文件/目錄
共同特點是:遇見文件不加參數,遇到目錄:-R(遞歸,修改目錄內所有
件的屬性)
實例:繼承:
[[email protected] tmp]# mkdir test1
[[email protected] tmp]# ll -ad test1/
drwxr-xr-x. 2 root root 6 Sep 10 11:33 test1/
[[email protected] tmp]# chmod -Rf 777 test1/
[[email protected] tmp]# ll -ad test1/
drwxrwxrwx. 2 root root 6 Sep 10 11:33 test1/
[[email protected] tmp]# chmod -Rf g+s test1/ #給予GID權限
[[email protected] tmp]# ll -ad test1/
drwxrwsrwx. 2 root root 6 Sep 10 11:33 test1/
[[email protected] tmp]# su - linuxs
Last login: Sun Sep 10 11:21:49 CST 2017 on pts/0
[[email protected] ~]$ cd /tmp
[[email protected] tmp]$ cd test1/
[[email protected] test1]$ echo "Test" > test
[[email protected] test1]$ ll
total 4
-rw-rw-r--. 1 linuxs root 5 Sep 10 11:51 test
SBIT:只可以管理自己的數據而不能刪除別人的文件(僅對目錄有效)
叫做SBIT位,也叫特殊權限之粘滯位
實例:
[[email protected] tmp]# su - linuxs
Last login: Sun Sep 10 11:51:03 CST 2017 on pts/0
[[email protected] ~]$
[[email protected] ~]$ cd /tmp/
[[email protected] tmp]$ ll -ad
drwxrwxrwt. 7 root root 88 Sep 10 11:57 .
[[email protected] tmp]$ # t代表粘滯位
[[email protected] tmp]$ echo "123" > test1
[[email protected] tmp]$ chmod 777 test1
[[email protected] tmp]$ ll -a test1
-rwxrwxrwx. 1 linuxs linuxs 4 Sep 10 11:58 test1
[[email protected] tmp]$ su - blacklist
[[email protected] ~]$ cd /tmp/
[[email protected] tmp]$ rm test1
rm: cannot remove ‘test1’: Operation not permitted
[blacklist[email protected] tmp]$ ll -a test1
-rwxrwxrwx. 1 linuxs linuxs 4 Sep 10 11:58 test1
linux[基礎]-20-用戶與文件權限-[文件特殊權限]-[01]