成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

聊聊Restorecon 命令使用實例

系統 Linux
當你將自定義文件添加到已經由SELinux策略管理的目錄中時,如果自定義文件沒有適當的SELinux上下文,那么將不會得到預期的結果。restorerecon命令的意思是恢復SELinux上下文。

[[404011]]

當你將自定義文件添加到已經由SELinux策略管理的目錄中時,如果自定義文件沒有適當的SELinux上下文,那么將不會得到預期的結果。restorerecon命令的意思是恢復SELinux上下文。restorecon命令將文件和目錄的SELinux安全上下文重置為默認值。這只會重置SELinux上下文的類型屬性。

1. 恢復文件的SELinux上下文

在以下示例中,index.html文件在SELinux上下文中具有“user_home_t”上下文類型。這個上下文類型,apache服務將無法訪問。

  1. [root@localhost ~]# ll -Z /var/www/html/index.html  
  2. -rw-rw-r--. root root unconfined_u:object_r:user_home_t:s0  13 Jan  7 11:14  /var/www/html/index.html 

注意:

上面的ls命令中的-Z選項將顯示特定文件的SELinux上下文。當我們使用restorecon命令時,我們實際上不需要知道文件的原始安全上下文。restorecon會自動修正。

以下示例將把index.html的安全性上下文恢復為適當的值。如下所示,它已將SELinux上下文的類型重置為“httpd_sys_content_t”, 現在apache將能夠為該文件提供服務,而不會出現任何錯誤。

  1. [root@localhost ~]# restorecon /var/www/html/index.html  
  2. [root@localhost ~]# ll -Z /var/www/html/index.html  
  3. -rw-r--r--. 1 root root unconfined_u:object_r:httpd_sys_content_t:s0 13 Jan  7 11:14 /var/www/html/index.html 

2. 更改安全上下文時輸出信息

默認情況下,執行restorecon命令時,它不會提示是否更改了文件的安全上下文。

  1. [root@localhost ~]# restorecon -v /var/www/html/index.html  
  2. Relabeled /var/www/html/index.html from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 

3. 使用通配符處理多個對象

下面實例將修改目錄下面所有文件的安全上下文。

  1. [root@localhost ~]# restorecon -v /var/www/html/* 

4. 遞歸處理文件和目錄

還可以使用-R選項遞歸重置文件的安全上下文。

  1. [root@localhost ~]# restorecon -Rv /var/www/html/ 
  2. Relabeled /var/www/html/sales from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  3. Relabeled /var/www/html/sales/graph.html from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 

5. 根據輸入文件還原上下文

可以將需要恢復安全上下文的文件或文件夾路徑保存在文件里,使用-f選項指定文件,來恢復。在下面的/var/www/html/testdir目錄和下面的指定的文件需要恢復默認安全上下文:

首先創建一個文件input.txt,在里面填入需要恢復默認安全上下文的目錄或者文件的完整路徑。

  1. [root@localhost ~]# vim input.txt  
  2. [root@localhost ~]# cat input.txt  
  3. /var/www/html/testdir 
  4. /var/www/html/testdir/file1.txt 
  5. /var/www/html/testdir/file3.txt 
  6. /var/www/html/testdir/file5.txt 
  7. /var/www/html/testdir/file7.txt 
  8. /var/www/html/testdir/file9.txt 

下面使用restorecon來恢復:

  1. [root@localhost ~]# restorecon -Rvf input.txt  
  2. Relabeled /var/www/html/testdir from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  3. Relabeled /var/www/html/testdir/file1.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  4. Relabeled /var/www/html/testdir/file2.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  5. Relabeled /var/www/html/testdir/file3.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  6. Relabeled /var/www/html/testdir/file4.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  7. Relabeled /var/www/html/testdir/file5.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  8. Relabeled /var/www/html/testdir/file6.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  9. Relabeled /var/www/html/testdir/file7.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  10. Relabeled /var/www/html/testdir/file8.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  11. Relabeled /var/www/html/testdir/file9.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 
  12. Relabeled /var/www/html/testdir/file10.txt from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 

6. 排除某個目錄

還可以使用-e選項排除不需要恢復安全上下文的目錄。

在以下示例中,我們正在處理/var/www/html 目錄下的所有文件,但不包括/var/www/html/sales子目錄中的文件。

  1. [root@localhost html]# restorecon -e /var/www/html/sales -Rv /var/www/html 

還可以提供多個-e選項來排除多個文件或文件夾。

總 結

restorecon命令將文件和目錄的SELinux安全上下文重置為默認值。這只會重置SELinux上下文的類型屬性。

本文轉載自微信公眾號「Linux就該這么學」,可以通過以下二維碼關注。轉載本文請聯系Linux就該這么學公眾號。

 

責任編輯:武曉燕 來源: Linux就該這么學
相關推薦

2022-04-11 07:50:58

top 命令Java 系統JVM 進程

2021-08-12 18:49:41

DataStreamAPI注冊

2021-02-11 08:27:28

數據

2010-10-26 10:02:05

oracle備份命令

2021-05-31 15:53:57

CPU Top命令

2021-08-10 11:45:57

topCPULinux

2021-01-04 05:43:59

LinuxBasename命令

2022-02-08 12:19:36

LinuxJQ命令

2010-06-22 13:23:18

Linux at命令詳

2022-02-22 08:00:48

JavaNIOBuffer

2022-01-19 22:14:36

Apache APIAPI 網關插件

2023-09-27 07:33:48

Docker命令容器

2022-07-12 08:00:31

命令Kubernetes應用程序

2022-02-15 07:26:31

Ncat工具Linux

2020-05-06 22:07:53

UbuntuLinux操作系統

2021-11-29 10:24:56

WasmEnvoy 負載均衡

2024-03-06 11:38:12

Appwrite方式Supabase

2021-02-07 23:58:10

單例模式對象

2022-03-11 20:46:01

機制命令kerberos

2023-10-27 08:59:00

網絡wiresharkIO
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 精品电影| 天天躁日日躁狠狠很躁 | 欧美vide | 久久99蜜桃综合影院免费观看 | 超碰国产在线 | 亚洲视频国产 | 殴美黄色录像 | 国产欧美一区二区三区另类精品 | 欧美成人在线免费 | 国产精品久久久久久久模特 | 狠狠操狠狠色 | 国产精品久久网 | 女女百合av大片一区二区三区九县 | 国产福利视频 | 久久艹免费视频 | 国产真实乱对白精彩久久小说 | 国产日批| 亚洲欧美日韩在线不卡 | 亚洲精品一区二区三区蜜桃久 | 日韩一区二区三区av | 99精品观看| 免费能直接在线观看黄的视频 | 国产91精品网站 | 国产欧美视频一区 | 精品美女在线观看视频在线观看 | 国产精品久久久久久久久 | 欧美一级欧美三级在线观看 | 97在线观视频免费观看 | 国产欧美一区二区三区在线看 | 国产精品视频yy9299一区 | 成人午夜激情 | 在线观看第一区 | 中文字幕在线免费视频 | 午夜精品久久久久久不卡欧美一级 | 欧美日韩久 | 亚洲精品乱码久久久久久9色 | 日韩精品免费在线观看 | 精品国产欧美日韩不卡在线观看 | 国产一区不卡 | 成年人网站免费视频 | 久热m3u8 |