天天看點

玩轉Redhat Linux 8.0系列 | 從指令行管理檔案系統權限

作者:熱愛程式設計的通信人

素材來源:Redhat Linux 8.0教育訓練教材《RH124》、《RH134》和《RH294》

玩了5-6年的Linux,現在再來溫習一遍RHCE教育訓練教材,按照指導完成實驗并與大家分享。

附上彙總貼:玩轉Redhat Linux 8.0系列 | 合集_熱愛程式設計的通信人的部落格-CSDN部落格

1 從workstation,使用ssh指令以student使用者身份登入servera。

[student@workstation ~]$ ssh student@servera
student@servera's password: 
Activate the web console with: systemctl enable --now cockpit.socket

This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Sun May 21 19:34:35 2023 from fe80::20c:29ff:fe3b:5822%ens33
[student@servera ~]$            

2 将redhat用作密碼,切換到root使用者。

[student@servera ~]$ su -
Password: 
[root@servera ~]#            

3 使用mkdir指令來建立/home/consultants目錄。

[root@servera ~]# mkdir /home/consultants
[root@servera ~]#            

4 使用chown指令, 将consultants目錄的組所有權更改給consultants。

[root@servera ~]# chown :consultants /home/consultants
[root@servera ~]#            

5 確定consultants組的權限允許組成員在/home/consultants目錄中建立和删除檔案。這些權限應禁止其他人通路檔案。

5.1 使用ls指令, 确認consultants組的權限允許組成員在/home/consultants目錄中建立和删除檔案。

[root@servera ~]# ls -ld /home/consultants
drwxr-xr-x. 2 root consultants 6 May 21 19:37 /home/consultants
[root@servera ~]#            

注意consultants組目前沒有寫入權限。

5.2 使用chmod指令, 為consultants組添加寫入權限。

[root@servera ~]# chmod g+w /home/consultants
[root@servera ~]# ls -ld /home/consultants
drwxrwxr-x. 2 root consultants 6 May 21 19:37 /home/consultants
[root@servera ~]#            

5.3 使用chmod指令, 禁止其他人通路/home/consultants目錄中的檔案。

[root@servera ~]# chmod 770 /home/consultants
[root@servera ~]# ls -ld /home/consultants
drwxrwx---. 2 root consultants 6 May 21 19:37 /home/consultants
[root@servera ~]#            

6 退出root shell并切換到consultant1使用者。密碼是redhat。

[root@servera ~]# exit
logout
[student@servera ~]$ su - consultant1
Password: 
[consultant1@servera ~]$            

7 前往/home/consultants目錄, 再建立一個名為consultant1.txt的檔案。

7.1 使用cd指令更改到/home/consultants目錄。

[consultant1@servera ~]$ cd /home/consultants
[consultant1@servera consultants]$            

7.2 使用touch指令, 建立一個名為consultant1.txt的空檔案。

[consultant1@servera consultants]$ touch consultant1.txt
[consultant1@servera consultants]$            

8 使用ls -l指令,列出新檔案的預設使用者群組所有權及其權限。

[consultant1@servera consultants]$ ls -l consultant1.txt 
-rw-rw-r--. 1 consultant1 consultant1 0 May 21 19:44 consultant1.txt
[consultant1@servera consultants]$            

9 確定consultants組的所有成員都可以編輯consultant1.txt檔案。将consultant1.txt檔案的組所有權更改給consultants。

9.1 使用chown指令, 将consultant1.txt檔案的組所有權更改給consultants。

[consultant1@servera consultants]$ chown :consultants consultant1.txt 
[consultant1@servera consultants]$            

9.2 使用ls指令及-l選項,列出consultant1.txt檔案的新所有權。

[consultant1@servera consultants]$ ls -l consultant1.txt 
-rw-rw-r--. 1 consultant1 consultants 0 May 21 19:44 consultant1.txt
[consultant1@servera consultants]$            

10 退出shell并切換到consultant2使用者。密碼是redhat。

[consultant1@servera consultants]$ exit
logout
[student@servera ~]$ su - consultant2
Password: 
[consultant2@servera ~]$            

11 前往/home/consultants目錄。確定consultant2使用者可以向consultant 1.txt檔案添加内容。退出shell。

11.1 使用cd指令更改到/home/consultants目錄。使用echo指令添加text到consultant1.txt檔案中。

[consultant2@servera ~]$ cd /home/consultants/
[consultant2@servera consultants]$ echo "text" >> consultant1.txt
[consultant2@servera consultants]$            

11.2 使用cat指令驗證該文本是否已添加到consultant1.txt檔案中。

[consultant2@servera consultants]$ cat consultant1.txt 
text
[consultant2@servera consultants]$           

11.3 退出shell。

[consultant2@servera consultants]$ exit
logout
[student@servera ~]$            

12 從servera登出。

[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$