---
# System prepended metadata

title: （五）SELinux設定

---

# （五）SELinux設定
## 設定82port
開啟kvm8
```
$ vim  /etc/httpd/conf/httpd.conf
```
```dockerfile=
#執行結果
#找到下面內容並修改

#Listen 12.34.56.78:80
Listen 82
```

修改完後重新啟動
```
$ systemctl restart httpd
```
重啟後會顯示fail
要新增82port才能夠正常啟動（即題目要求）
```
$ semanage port -a -t http_port_t -p tcp 82
```

><font color="navy">-a是新增 -d是刪除</font>

新增後
```
$ systemctl restart httpd
```
重新啟動後fail就會變成active
## file1 & file2 設定
用server中的firefox瀏覽器開啟google drive下載file1,file2檔案
開啟Files資料夾，把檔案放置/var/www/html中
```
$ scp /var/www/html/file1.html root@kvm8.chuck.im.shu:/var/www/html/
```
```
$ scp /var/www/html/file2.html root@kvm8.chuck.im.shu:/var/www/html/
```
開啟kvm8
:::warning
複製檔案後先ll確認資料夾內是否有檔案
修改file1的type
:::
```
$ semanage fcontext -a -t admin_home_t "/var/www/html/file1.html"
```
```
$ restorecon -Rv /var/www/html
```
```
$ ll -Z /var/www/html/
```
```dockerfile=
#執行結果
total 8
-rw-r--r--. 1 root root unconfined_u:object_r:admin_home_t:s0        9 Aug  2 23:09 file1.html
-rw-r--r--. 1 root root unconfined_u:object_r:httpd_sys_content_t:s0 9 Aug  2 23:09 file2.html
```
:::danger
確認type是否改為admin_home_t
:::
```
$ cat /etc/selinux/targeted/contexts/files/file_contexts.local
```
```dockerfile=
#執行結果

# This file is auto-generated by libsemanage
# Do not edit directly.

/var/www/html/file1.html    system_u:object_r:admin_home_t:s0
```
:::warning
要確認是否有最後一行跳出
:::
測試file1設定是否成功
```
$ curl http://127.0.0.1:82/file1.html
```
```dockerfile=
#執行結果
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
</body></html>
```
:::success
出現錯誤訊息就代表設定成功
:::