

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 變更為 `enforcing` 模式
<a name="enforcing-mode"></a>

當您SELinux在 `enforcing` 模式下執行時，SELinux公用程式是`enforcing`設定的政策。 會根據政策的規則允許或拒絕存取，以SELinux控管特定應用程式的功能。

若要尋找目前的SELinux模式，請執行 `getenforce`命令。

```
getenforce
Permissive
```

## 編輯設定檔案以啟用 `enforcing` 模式
<a name="config-file-enforcing"></a>

若要將 模式變更為 `enforcing`，請使用下列步驟。

1. 編輯 `/etc/selinux/config` 檔案以變更為 `enforcing` 模式。`SELINUX` 設定應如下所示。

   ```
   SELINUX=enforcing
   ```

1. 重新啟動系統以完成對 `enforcing` 模式的變更。

   ```
   $ sudo reboot
   ```

在下一次開機時， 會SELinux重新標記系統中的所有檔案和目錄。 SELinux也會新增當 SELinux為 時所建立之檔案和目錄SELinux的內容`disabled`。

變更為 `enforcing` 模式後， SELinux可能會因為不正確或缺少SELinux政策規則而拒絕某些動作。您可以使用下列命令檢視SELinux拒絕的動作。

```
$ sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent
```

## 使用 cloud-init 來啟用 `enforcing` 模式
<a name="cloud-init-enforcing"></a>

或者，當您啟動執行個體時，請將下列 `cloud-config` 作為使用者資料傳遞以啟用 `enforcing` 模式。

```
#cloud-config
selinux: 
  mode: enforcing
```

預設情況下，此設定會導致執行個體重新啟動。為了提高穩定性，建議您重新啟動執行個體 但是，您可以依照偏好輸入下列 `cloud-config`，以跳過重新開機。

```
#cloud-config
selinux:
  mode: enforcing
  selinux_no_reboot: 1
```