15_目錄,檔案許可權
阿新 • • 發佈:2020-11-30
許可權的基本概述
什麼是許可權 系統對使用者所能執行的功能的限制 為什麼要有許可權 為了保護每個使用者的自己的工作環境和隱私 許可權跟使用者有什麼關係 屬主 User u 屬組 Group g 其他人 others o a 所有 對應了三個基礎許可權 r 可讀 readable 4 w 可寫 writable 2 x 可執行 executable 1 - 沒有許可權 許可權位佔位符 0 [root@qls ~]# ls -l total 61152 -rw-r--r--. 1 root root 39 Jul 17 19:16 123.txt -rw-r--r--. 1 root root 9272936 Jul 17 12:01 access.log - rw- r-- r-- 644 檔案的型別 屬主 屬組 匿名 每三個為一組 第一個對應 可讀 r 第二個對應 可寫 w 第三個對應 可執行 x 沒有此許可權則用-代替 為什麼要設定許可權,如何設定許可權 設定某個使用者對於系統的某個資源擁有什麼樣管理權力 chmod #設定許可權的命令 選項: -R #針對目錄設定許可權 賦予目錄及目錄以下所有檔案的許可權 只有root管理員才可以修改任何人的許可權 普通使用者只能修改自己的許可權
許可權的設定案例
-rwxrw-r-- test01 dev file.txt test01 user01屬於dev組 qls01屬於qls01組 三個使用者分別對這個檔案擁有什麼許可權 test01是檔案的所有者 可讀 可寫 可執行許可權 user01屬於dev組,dev組所擁有的許可權,user01同樣擁有 可讀 可寫 許可權 qls01不屬於dev組,對於此檔案來說,就是一個陌生人 擁有匿名使用者的許可權 可讀 判斷一個使用者對一個檔案擁有什麼許可權 1. 系統會判斷該使用者是否為所有者,如果是,則按照屬主的許可權進行訪問 2. 如果不是所有者,則判斷該使用者是否為所屬組,如果是,則按照所屬組的許可權進行訪問 3. 如果此使用者不是所有者,也不是所屬組,則按照匿名使用者進行訪問 修改許可權的兩種方法: 字母進行修改 u 屬主 g 屬組 o 匿名使用者 a 所有使用者 許可權字母 r 可讀 w 可寫 x 可執行 - 沒有許可權 賦予的方式 + #新增許可權 - #收回某個許可權 = #覆蓋之前的許可權 #新增許可權 [root@qls ~]# ll total 4 -rw-r--r-- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod u+x hosts [root@qls ~]# ll total 4 -rwxr--r-- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod g+wx hosts [root@qls ~]# ll total 4 -rwxrwxr-- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod o+w hosts [root@qls ~]# ll total 4 -rwxrwxrw- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod a+x hosts [root@qls ~]# ll total 4 -rwxrwxrwx 1 root root 158 Jul 23 09:06 hosts #收回許可權 #a可以省略 [root@qls ~]# chmod -x hosts [root@qls ~]# ll total 4 -rw-rw-rw- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod u-w hosts [root@qls ~]# ll total 4 -r--rw-rw- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod g-w,o-rw hosts [root@qls ~]# ll total 4 -r--r----- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# #覆蓋之前的所有許可權 [root@qls ~]# chmod a=rw hosts [root@qls ~]# ll total 4 -rw-rw-rw- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# chmod o=- hosts [root@qls ~]# ll total 4 -rw-rw---- 1 root root 158 Jul 23 09:06 hosts 根據數字進行修改 會把原來的許可權全部覆蓋掉 -R #給目錄的許可權及目錄以下的所有檔案或者子目錄都設定統一許可權 [root@qls ~]# chmod 644 hosts [root@qls ~]# ll total 4 -rw-r--r-- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# mkdir data [root@qls ~]# ll total 4 drwxr-xr-x 2 root root 6 Jul 23 09:35 data -rw-r--r-- 1 root root 158 Jul 23 09:06 hosts [root@qls ~]# cp /etc/hosts data/ [root@qls ~]# ll data/ total 4 -rw-r--r-- 1 root root 158 Jul 23 09:35 hosts [root@qls ~]# ll -d data/ drwxr-xr-x 2 root root 19 Jul 23 09:35 data/ [root@qls ~]# chmod 700 data/ [root@qls ~]# ll -d data/ drwx------ 2 root root 19 Jul 23 09:35 data/ [root@qls ~]# ll data/ total 4 -rw-r--r-- 1 root root 158 Jul 23 09:35 hosts [root@qls ~]# chmod -R 755 data/ [root@qls ~]# ll -d data/ drwxr-xr-x 2 root root 19 Jul 23 09:35 data/ [root@qls ~]# ll data/ total 4 -rwxr-xr-x 1 root root 158 Jul 23 09:35 hosts #許可權設定案例 /opt/test 針對於此目錄 屬主為root 屬組為dev dev01 dev02 屬主擁有所有許可權 屬組擁有可讀 可寫許可權 其他人沒有任何許可權 [root@qls ~]# mkdir /opt/test [root@qls ~]# ll /opt/ total 0 drwxr-xr-x 2 root root 6 Jul 23 09:40 test [root@qls ~]# groupadd dev [root@qls ~]# chgrp dev /opt/test/ [root@qls ~]# ll /opt/ total 0 drwxr-xr-x 2 root dev 6 Jul 23 09:40 test [root@qls ~]# chmod 760 /opt/test/ [root@qls ~]# ll /opt/ total 0 drwxrw---- 2 root dev 6 Jul 23 09:40 test
許可權對檔案或目錄的影響
許可權對檔案或者目錄的影響
許可權 檔案 目錄
r 可以檢視檔案內容 cat head tail 瀏覽目錄及子目錄的列表 ls tree
w 可以新增,修改檔案內容的權利 vim echo > >> 可以新建或者刪除,移動目錄中的檔案的權利
x 可以執行檔案的權利 指令碼 可以進入目錄 cd
檔案許可權設定案例
r許可權 [root@qls ~]# echo "hostname" >> /opt/file.txt [root@qls ~]# ll /opt/ total 4 -rw-r--r-- 1 root root 9 Jul 23 09:57 file.txt [root@qls ~]# useradd qls01 [root@qls ~]# [root@qls ~]# echo "1" | passwd --stdin qls01 Changing password for user qls01. passwd: all authentication tokens updated successfully. [root@qls ~]# su - qls01 Last login: Thu Jul 23 09:59:14 CST 2020 on pts/0 [qls01@qls ~]$ ll /opt/ total 4 -rw-r--r-- 1 root root 9 Jul 23 09:57 file.txt drwxrw---- 2 root dev 6 Jul 23 09:40 test [qls01@qls ~]$ cat /opt/file.txt hostname [qls01@qls ~]$ head /opt/file.txt hostname [qls01@qls ~]$ tail /opt/file.txt hostname [qls01@qls ~]$ vim /opt/file.txt [qls01@qls ~]$ echo "123" >> /opt/file.txt -bash: /opt/file.txt: Permission denied [qls01@qls ~]$ /opt/file.txt -bash: /opt/file.txt: Permission denied #檔案只有r許可權時,是可以正常檢視檔案內容的,不可以修改或者執行檔案的許可權 w許可權 [root@qls ~]# chmod o=w /opt/file.txt [root@qls ~]# ll /opt/file.txt -rw-r---w- 1 root root 9 Jul 23 09:57 /opt/file.txt [root@qls ~]# su - qls01 Last login: Thu Jul 23 10:00:14 CST 2020 on pts/0 [qls01@qls ~]$ cat /opt/file.txt cat: /opt/file.txt: Permission denied [qls01@qls ~]$ vim /opt/file.txt [qls01@qls ~]$ cat /opt/file.txt cat: /opt/file.txt: Permission denied [qls01@qls ~]$ /opt/file.txt -bash: /opt/file.txt: Permission denied [root@qls ~]# cat /opt/file.txt uirethruie [qls01@qls ~]$ echo "test" >> /opt/file.txt [qls01@qls ~]$ echo "test" > /opt/file.txt [root@qls ~]# cat /opt/file.txt uirethruie test [root@qls ~]# cat /opt/file.txt test #只有w許可權時, 無法檢視和執行檔案的許可權 使用vim編輯檔案檔案時,無法檢視裡面的內容,可以進行編輯,但是需要強制儲存,但是儲存之後,原來的內容被覆蓋了 可以使用echo命令進行追加或者重定向內容進去 x許可權 [root@qls ~]# chmod o=x /opt/file.txt [root@qls ~]# ll /opt/file.txt -rw-r----x 1 root root 5 Jul 23 10:09 /opt/file.txt [root@qls ~]# su - qls01 Last login: Thu Jul 23 10:08:38 CST 2020 on pts/0 [qls01@qls ~]$ ll /opt/file.txt -rw-r----x 1 root root 5 Jul 23 10:09 /opt/file.txt [qls01@qls ~]$ cat /opt/file.txt cat: /opt/file.txt: Permission denied [qls01@qls ~]$ echo "123" >> /opt/file.txt -bash: /opt/file.txt: Permission denied [qls01@qls ~]$ /opt/file.txt bash: /opt/file.txt: Permission denied #檔案只有x許可權 什麼都幹不了 rw許可權 [root@qls ~]# chmod o=rw /opt/file.txt [root@qls ~]# ll /opt/file.txt -rw-r--rw- 1 root root 5 Jul 23 10:09 /opt/file.txt [root@qls ~]# su - qls01 Last login: Thu Jul 23 10:11:27 CST 2020 on pts/0 [qls01@qls ~]$ cat /opt/file.txt test [qls01@qls ~]$ echo "hostname" > /opt/file.txt [qls01@qls ~]$ vim /opt/file.txt [qls01@qls ~]$ cat /opt/file.txt hostname pwd [qls01@qls ~]$ /opt/file.txt -bash: /opt/file.txt: Permission denied #經過測試,檔案w許可權需要r許可權的配合 才能正常的修改檔案內容 rx許可權 [root@qls ~]# chmod o=rx /opt/file.txt [root@qls ~]# ll /opt/file.txt -rw-r--r-x 1 root root 13 Jul 23 10:14 /opt/file.txt [root@qls ~]# su - qls01 Last login: Thu Jul 23 10:14:16 CST 2020 on pts/0 [qls01@qls ~]$ cat /opt/file.txt hostname pwd [qls01@qls ~]$ echo "123" > /opt/file.txt -bash: /opt/file.txt: Permission denied [qls01@qls ~]$ vim /opt/file.txt [qls01@qls ~]$ /opt/file.txt qls /home/qls01 #經過測試,檔案的x許可權需要r許可權的配合 wx許可權 沒有什麼用處 rwx許可權 許可權太大 Permission denied #許可權不足 沒有許可權 總結: 許可權對檔案的影響 r:檔案可以讀取內容,不能寫,不能執行 w:檔案可以寫入內容,但是追加只能>>,不能vim,因為不能讀取內容,所以不能修改檔案內容,只能覆蓋 x:啥也不能幹,因為沒有讀許可權。所以無法執行檔案中的內容 rw:可讀,可寫,不能執行 rx:可讀,可執行,不能寫 rwx:可讀,可寫,可執行 注意:檔案的rwx許可權,只能針對檔案內容,如果想要刪除,或者移動,那麼跟檔案所在目錄的許可權有關
目錄許可權設定案例
許可權對目錄的影響
r許可權 具有可以瀏覽目錄及其子目錄下的列表 屬性資訊
[root@qls ~]# chmod o=r /opt/test/
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw-r-- 2 root root 6 Jul 23 09:40 test
[root@qls ~]# touch /opt/test/data.{txt,log,sh}
[root@qls ~]# mkdir /opt/test/oldboy{01..03}
[root@qls ~]# ll /opt/test/
total 0
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.log
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.sh
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.txt
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy01
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy02
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy03
[root@qls ~]# su - qls01
Last login: Thu Jul 23 10:51:09 CST 2020 on pts/0
[qls01@qls ~]$ ls /opt/test/
ls: cannot access /opt/test/data.txt: Permission denied
ls: cannot access /opt/test/data.log: Permission denied
ls: cannot access /opt/test/data.sh: Permission denied
ls: cannot access /opt/test/oldboy01: Permission denied
ls: cannot access /opt/test/oldboy02: Permission denied
ls: cannot access /opt/test/oldboy03: Permission denied
data.log data.sh data.txt oldboy01 oldboy02 oldboy03
[qls01@qls ~]$ ls -l /opt/test/
ls: cannot access /opt/test/data.txt: Permission denied
ls: cannot access /opt/test/data.log: Permission denied
ls: cannot access /opt/test/data.sh: Permission denied
ls: cannot access /opt/test/oldboy01: Permission denied
ls: cannot access /opt/test/oldboy02: Permission denied
ls: cannot access /opt/test/oldboy03: Permission denied
total 0
-????????? ? ? ? ? ? data.log
-????????? ? ? ? ? ? data.sh
-????????? ? ? ? ? ? data.txt
d????????? ? ? ? ? ? oldboy01
d????????? ? ? ? ? ? oldboy02
d????????? ? ? ? ? ? oldboy03
[qls01@qls ~]$ rm -f /opt/test/data.log
rm: cannot remove ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ touch /opt/test/data.conf
touch: cannot touch ‘/opt/test/data.conf’: Permission denied
[qls01@qls ~]$ mv /opt/test/data.log /tmp
mv: cannot stat ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ cd /opt/test/
-bash: cd: /opt/test/: Permission denied
[qls01@qls ~]$ tree /opt/test/ #沒有任何統計
/opt/test/
0 directories, 0 files
#目錄只有r許可權,使用ls -l命令檢視目錄下的列表,會出現一堆的許可權不足,但是檔名和檔案型別顯示出來了,其他的屬性資訊都是問號 不能對此目錄下的檔案進行新建或者刪除及其移動的操作 也不能切換到這個目錄
w許可權
[root@qls ~]# chmod o=w /opt/test/
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw--w- 5 root root 101 Jul 23 10:51 test
[root@qls ~]# su - qls01
Last login: Thu Jul 23 10:52:22 CST 2020 on pts/0
[qls01@qls ~]$ ls /opt/test/
ls: cannot open directory /opt/test/: Permission denied
[qls01@qls ~]$ ls -l /opt/test/
ls: cannot open directory /opt/test/: Permission denied
[qls01@qls ~]$ cd /opt/test/
-bash: cd: /opt/test/: Permission denied
[qls01@qls ~]$ touch /opt/test/123.txt
touch: cannot touch ‘/opt/test/123.txt’: Permission denied
[qls01@qls ~]$ rm -f /opt/test/data.log
rm: cannot remove ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ mv /opt/test/data.log /tmp/
mv: cannot stat ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ cp /opt/test/data.log /tmp
cp: cannot stat ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ cp /opt/test/data.log /tmp
cp: cannot stat ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ mv /opt/test/data.log /tmp/
mv: cannot stat ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ rm -f /opt/test/data.log
rm: cannot remove ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ ll -d /opt/
drwxrwxrwx 3 root root 34 Jul 23 09:57 /opt/
#只有w許可權時,目錄什麼都做不了
x許可權 進入目錄
[root@qls ~]# su - qls01
Last login: Thu Jul 23 10:57:51 CST 2020 on pts/0
[qls01@qls ~]$ cd /opt/test/
[qls01@qls test]$ ls
ls: cannot open directory .: Permission denied
[qls01@qls test]$ ls -l
ls: cannot open directory .: Permission denied
[qls01@qls test]$ rm -f data.log
rm: cannot remove ‘data.log’: Permission denied
[qls01@qls test]$ touch data.conf
touch: cannot touch ‘data.conf’: Permission denied
[qls01@qls test]$ mv data.log /tmp/
mv: cannot move ‘data.log’ to ‘/tmp/data.log’: Permission denied
[qls01@qls test]$ cp data.log /tmp/
[qls01@qls test]$ ll /tmp/
total 4
drwxr-xr-x. 2 root root 51 Jul 17 17:59 data1
drwxr-xr-x. 2 root root 51 Jul 17 17:59 data2
drwxr-xr-x. 2 root root 51 Jul 17 17:59 data3
-rw-r--r-- 1 qls01 qls01 0 Jul 23 11:03 data.log
#目錄只有x許可權時,可以切換到目錄中,無法檢視目錄列表資訊 也無法進行刪除、新建、移動等操作 可以進行復制操作
rw許可權
[root@qls ~]# chmod o=rw /opt/test/
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw-rw- 5 root root 101 Jul 23 10:51 test
[root@qls ~]# su - qls01
Last login: Thu Jul 23 11:06:21 CST 2020 on pts/0
[qls01@qls ~]$ cd /opt/test/
-bash: cd: /opt/test/: Permission denied
[qls01@qls ~]$ ls /opt/test/
ls: cannot access /opt/test/data.txt: Permission denied
ls: cannot access /opt/test/data.log: Permission denied
ls: cannot access /opt/test/data.sh: Permission denied
ls: cannot access /opt/test/oldboy01: Permission denied
ls: cannot access /opt/test/oldboy02: Permission denied
ls: cannot access /opt/test/oldboy03: Permission denied
data.log data.sh data.txt oldboy01 oldboy02 oldboy03
[qls01@qls ~]$ ls -l /opt/test/
ls: cannot access /opt/test/data.txt: Permission denied
ls: cannot access /opt/test/data.log: Permission denied
ls: cannot access /opt/test/data.sh: Permission denied
ls: cannot access /opt/test/oldboy01: Permission denied
ls: cannot access /opt/test/oldboy02: Permission denied
ls: cannot access /opt/test/oldboy03: Permission denied
total 0
-????????? ? ? ? ? ? data.log
-????????? ? ? ? ? ? data.sh
-????????? ? ? ? ? ? data.txt
d????????? ? ? ? ? ? oldboy01
d????????? ? ? ? ? ? oldboy02
d????????? ? ? ? ? ? oldboy03
[qls01@qls ~]$ touch /opt/test/data.conf
touch: cannot touch ‘/opt/test/data.conf’: Permission denied
[qls01@qls ~]$ rm -f /opt/test/data.log
rm: cannot remove ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ mv /opt/test/data.log /tmp/
mv: cannot stat ‘/opt/test/data.log’: Permission denied
[qls01@qls ~]$ cp /opt/test/data.txt /tmp/
cp: cannot stat ‘/opt/test/data.txt’: Permission denied
#rw許可權 跟只有r許可權作用是一樣的
rx許可權
[root@qls ~]# chmod o=rx /opt/test/
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw-r-x 5 root root 101 Jul 23 10:51 test
[root@qls ~]# su - qls01
Last login: Thu Jul 23 11:10:14 CST 2020 on pts/0
[qls01@qls ~]$ cd /opt/test/
[qls01@qls test]$ ls
data.log data.sh data.txt oldboy01 oldboy02 oldboy03
[qls01@qls test]$ ls -l
total 0
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.log
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.sh
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.txt
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy01
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy02
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy03
[qls01@qls test]$ touch data.conf
touch: cannot touch ‘data.conf’: Permission denied
[qls01@qls test]$ rm -f data.log
rm: cannot remove ‘data.log’: Permission denied
[qls01@qls test]$ mv data.txt /tmp/
mv: cannot move ‘data.txt’ to ‘/tmp/data.txt’: Permission denied
[qls01@qls test]$ cp data.txt /tmp/
[qls01@qls test]$ ll /tmp/
total 4
drwxr-xr-x. 2 root root 51 Jul 17 17:59 data1
drwxr-xr-x. 2 root root 51 Jul 17 17:59 data2
drwxr-xr-x. 2 root root 51 Jul 17 17:59 data3
-rw-r--r-- 1 qls01 qls01 0 Jul 23 11:03 data.log
-rw-r--r-- 1 qls01 qls01 0 Jul 23 11:13 data.txt
#目錄擁有rx許可權時,可以正常的檢視目錄列表資訊,屬性資訊,也可以進入目錄,可以複製檔案到其他目錄,但是不能執行新建、刪除、移動等操作
wx許可權
[root@qls ~]# chmod o=wx /opt/test/
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw--wx 5 root root 101 Jul 23 10:51 test
[root@qls ~]# su - qls01
Last login: Thu Jul 23 11:12:31 CST 2020 on pts/0
[qls01@qls ~]$ cd /opt/test/
[qls01@qls test]$ ls
ls: cannot open directory .: Permission denied
[qls01@qls test]$ touch 123.txt
[qls01@qls test]$ ls
ls: cannot open directory .: Permission denied
[qls01@qls test]$ rm -f data.log
[qls01@qls test]$ mv data.txt /tmp/
[qls01@qls test]$ ls
ls: cannot open directory .: Permission denied
#目錄擁有wx許可權時,可以進入目錄,可以新建,刪除、移動檔案的權利 但是檢視不了目錄的列表及屬性資訊
總結: 許可權對目錄的影響
對目錄設定許可權時,不能離開x許可權
對檔案設定許可權時,不能離開r許可權
r:可以檢視目錄下所有的檔名,但是看不見檔案的詳細資訊
rx:加上x許可權,就可以看見檔案的詳細資訊了
w:啥也不是
wx:可以建立,可以刪除,不能檢視
rw:可以檢視目錄下的檔案,但是不能刪除,不能移動,不能拷貝
rwx:刪除檔案,建立檔案,移動檔案,拷貝檔案,檢視
x:啥也不是
屬主屬組設定
chown #設定屬主屬組 只有root管理員才可以進行設定
選項:
-R #遞迴設定 設定目錄及其目錄以下的所有檔案
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw--wx 5 root root 84 Jul 23 11:17 test
[root@qls ~]# chown qls01 /opt/file.txt #預設設定的是屬主
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 qls01 root 13 Jul 23 10:14 file.txt
drwxrw--wx 5 root root 84 Jul 23 11:17 test
[root@qls ~]# chown .qls01 /opt/file.txt #設定屬組
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 qls01 qls01 13 Jul 23 10:14 file.txt
drwxrw--wx 5 root root 84 Jul 23 11:17 test
[root@qls ~]# chown root.root /opt/file.txt #同時設定屬主屬組
[root@qls ~]# ll /opt/
total 4
-rw-r--r-x 1 root root 13 Jul 23 10:14 file.txt
drwxrw--wx 5 root root 84 Jul 23 11:17 test
[root@qls ~]# chown qls01.qls01 /opt/test/ #只設置目錄
[root@qls ~]# ll -d /opt/test/
drwxrw--wx 5 qls01 qls01 84 Jul 23 11:17 /opt/test/
[root@qls ~]# ll /opt/test/
total 0
-rw-rw-r-- 1 qls01 qls01 0 Jul 23 11:17 123.txt
-rw-r--r-- 1 root root 0 Jul 23 10:51 data.sh
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy01
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy02
drwxr-xr-x 2 root root 6 Jul 23 10:51 oldboy03
[root@qls ~]# chown -R qls01.qls01 /opt/test/ #遞迴設定
[root@qls ~]# ll /opt/test/
total 0
-rw-rw-r-- 1 qls01 qls01 0 Jul 23 11:17 123.txt
-rw-r--r-- 1 qls01 qls01 0 Jul 23 10:51 data.sh
drwxr-xr-x 2 qls01 qls01 6 Jul 23 10:51 oldboy01
drwxr-xr-x 2 qls01 qls01 6 Jul 23 10:51 oldboy02
drwxr-xr-x 2 qls01 qls01 6 Jul 23 10:51 oldboy03
chgrp #設定屬組
[root@qls ~]# chgrp root /opt/test/
[root@qls ~]# ll -d /opt/test/
drwxrw--wx 5 qls01 root 84 Jul 23 11:17 /opt/test/
Umask控制權限
[root@qls ~]# ll
total 4
drwxr-xr-x 2 root root 6 Jul 23 11:21 123
-rw-r--r-- 1 root root 0 Jul 23 11:21 123.txt
系統中為什麼新建立的目錄的許可權為755,檔案的許可權為644
都是由系統的控制權限所控制的
umask #控制權限的命令
[root@qls ~]# umask
0022
系統中是如何計算許可權
系統新建立的目錄的許可權由最大許可權777減去umask控制權限022得到的就是755,所以說新建立的目錄的許可權為755,新建立檔案的許可權由檔案最大許可權666減去umask控制權限022,得到644許可權,所以說新建立的檔案的許可權為644,當檔案許可權遇到奇數時,在奇數為加一
[root@qls ~]# umask
0022
[root@qls ~]# umask 033
[root@qls ~]# umask
0033
[root@qls ~]# mkdir oldboy
[root@qls ~]# ll
total 4
drwxr-xr-x 2 root root 6 Jul 23 11:21 123
-rw-r--r-- 1 root root 0 Jul 23 11:21 123.txt
drwxr--r-- 2 root root 6 Jul 23 12:02 oldboy
[root@qls ~]# touch oldboy.txt
[root@qls ~]# ll
total 4
drwxr-xr-x 2 root root 6 Jul 23 11:21 123
-rw-r--r-- 1 root root 0 Jul 23 11:21 123.txt
drwxr--r-- 2 root root 6 Jul 23 12:02 oldboy
-rw-r--r-- 1 root root 0 Jul 23 12:02 oldboy.txt