第十四章 Linux中rwx許可權管理
阿新 • • 發佈:2020-08-01
許可權管理
許可權的基本管理
什麼是許可權 許可權就是系統對我們使用者所做的操作的一種限制
為什麼要有許可權 給系統操作使用者的許可權做一個拓展和規定
許可權的分類
[root@lxy ~]# ll
-rw-r--r--. 1 root root 25 Dec 15 00:58 123.txt
有9位基礎許可權
屬主的許可權 owner 前三位
屬組的許可權 group 中間的三位
其他人的許可權 others 後三位
每個分類又分為幾個不同額許可權
可讀 readable
可寫 writable
可執行 executable
讀 r 4
寫 w 2
執行 x 1
許可權佔位符(沒有許可權) - 0
1.判斷該使用者是否是此檔案的屬主,如果是,就按照屬主的許可權操作
2.判斷該使用者是否是此檔案的屬組,如果是,就按照屬組的許可權操作
3.該使用者對於此檔案來說,是陌生人,就使用其他的許可權操作
案例
-rwxr-xr--. 1 root test 13 Dec 15 00:54 pass6.txt
1.root使用者對此檔案的可以操作什麼
root是這個的屬主 可讀 可寫 可執行
2.dev使用者對此檔案可以操作什麼,已知,dev屬於test組
dev使用者屬於test組,該檔案的屬組是test dev使用者擁有此檔案的屬組的許可權 可讀 可執行
3.oldboy使用者對此檔案有什麼操作許可權
oldboy使用者對於此檔案來說,是陌生人,擁有陌生人的許可權 可讀
許可權的設定
chmod #設定許可權
-R #遞迴設定許可權
第一種設定許可權
根據字母設定許可權
u 屬主的許可權
g 屬組的許可權
o 其它的人的許可權
a 所有人的許可權
+ 新增許可權
- 移除許可權
= 覆蓋許可權
r 讀的許可權
w 寫的許可權
x 執行的許可權
- 沒有許可權
[root@lxy ~]# touch test.txt
[root@lxy ~]#
[root@lxy ~]# ll
total 0
-rw-r--r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod u+x test.txt
[root@lxy ~]# ll
total 0
-rwxr--r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod g+w test.txt
[root@lxy ~]# ll
total 0
-rwxrw-r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod o+x test.txt
[root@lxy ~]# ll
total 0
-rwxrw-r-x. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod o-x test.txt
[root@lxy ~]# ll
total 0
-rwxrw-r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod a+x test.txt
[root@lxy ~]# ll
total 0
-rwxrwxr-x. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod -x test.txt
[root@lxy ~]# ll
total 0
-rw-rw-r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod a=r test.txt
[root@lxy ~]# ll
total 0
-r--r--r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod u=rwx test.txt
[root@lxy ~]# ll
total 0
-rwxr--r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod g=x test.txt
[root@lxy ~]# ll
total 0
-rwx--xr--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod o=- test.txt
[root@lxy ~]# ll
total 0
-rwx--x---. 1 root root 0 Dec 17 17:21 test.txt
第二種
根據數字進行設定許可權
[root@lxy ~]# ll
total 0
-rwx--x---. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod 644 test.txt
[root@lxy ~]# ll
total 0
-rw-r--r--. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod 000 test.txt
[root@lxy ~]# ll
total 0
----------. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]# chmod 777 test.txt
[root@lxy ~]# ll
total 0
-rwxrwxrwx. 1 root root 0 Dec 17 17:21 test.txt
[root@lxy ~]