SELinux簡單配置
SELinux簡單配置
SELinux(Secrity-Enhanced Linux,安全增強式Linux)是一種強制存取控制的實現,它的作法是以最小許可權原則為基礎提供一些更強、更安全的強制存取控制架構來與核心的主要子系統共同動作。
SELinux等級有三個:
Enforcing: 強制的,如果違反則直接阻止
Permissive: 在違反規則時只警告,但是不阻止
Disables:表示 SELinux不啟用
在啟動SELinux時要重新啟動系統才能使用。
SELinux可以通過不同的方式進行啟動與關閉,也可以使它暫時的關閉與開啟
永久關閉方法:1>setupàFirewall configuration-SELinux 自己選擇開啟關閉
2>使用命令:[root@localhost ~]# system-config-securitylevel 也可以選擇
暫時關閉方法:setenforce 1 :暫時關閉SELinux
setenforce 0 :開啟SELinux Permissive
簡單檢視SELinux的狀態:
getenforce
SELinux中訪問控制屬性就叫安全上下文,所有的客體(如檔案,程式間通訊)和主體(程式)都有與其並聯的安全上下文,一個安全上下文由使用者、角色、和型別識別符號3個部分組成,如下命令可以看到檔案的安全上下文屬性
在SELlinux中安全上下文中的使用者和角色識別符號除了對強制有一點約束之外對型別強制訪問控制策略沒有任何影響。我們看一個小例子來說明一下型別識別符號的限制。
示例1 http的SELinux應用
[root@localhost www]# cd /mnt/cdrom/Server/
[root@localhost Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
warning: httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing… ################################### [100%]
1:httpd ################################### [100%]
現在我們可以正常的啟動http服務
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
但是我們如果修改一下http預設的主目錄,會出現怎麼樣的情況呢!
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
將<Directory “/var/www/html”> 修改為 <Directory “/html”>
建立目錄
[root@localhost ~]# mkdir /html
這時候我們再來重新啟動一次
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Syntax error on line 306 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:306: <Directory> was not closed.
[FAILED]
可以看到系統會出現錯誤,這個情況就屬於型別識別符號的使用
檢視一下/var/www/html的目錄識別符號
[root@localhost ~]# ll -dZ /var/www/html
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t /var/www/html
再檢視一下/html的目錄識別符號
[root@localhost ~]# ll -dZ /html
drwxr-xr-x root root root:object_r:default_t /html
可以看出/var/www/html的目錄識別符號屬於httpd域,而/html則屬於default_t,而httpd_t域執行的httpd程式只能監聽httpd_port-t型別的埠,並限制此域的程式只能存取標記為httpd_sys_content_t的網頁檔案,所以httpd服務不能正常啟動
但是並不是開啟了SELinux就不能夠改變主目錄的位置,我們可以把/html目錄修改為httpd_t的域,可以使用chcon命令來更改,我們把/html的域更改為httpd_t的域
[root@localhost ~]# chcon -t httpd_sys_content_t /html
[root@localhost ~]# ll -dZ /html
drwxr-xr-x root root root:object_r:httpd_sys_content_t /html
現在我們再次啟動一次http服務
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
啟動成功!!!!!!!
有時候我們又想改變http服務的埠,那麼應該怎麼辦,可以直接啟動嗎,我們可以嘗試著啟動一次
把伺服器埠更改為800
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
將Listen 80 改為: Listen 800
先安裝一個除錯工具
[root@localhost Server]# yum install setroubleshoot
啟動setroubleshoot服務
[root@localhost Server]# service setroubleshoot start
Starting setroubleshootd: [ OK ]
啟動http伺服器
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:800
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:800
no listening sockets available, shutting down
Unable to open logs [FAILED]
這次直接提示了:不能繫結本機的800埠,也可以檢視日誌
[root@localhost Server]# tail /var/log/messages 可以看到錯誤提示
Dec 27 00:51:56 localhost setroubleshoot: SELinux is preventing tpvmgp (cupsd_t) “execute_no_trans” to /usr/lib/vmware-tools/bin32/appLoader (lib_t). For complete SELinux messages. run sealert -l 383d449b-4b8c-49aa-b7f0-f19bb5499555
並且讓執行程式碼檢視清楚的錯誤資訊:sealert -l 383d449b-4b8c-49aa-b7f0-f19bb5499555,我們可以自行檢視其詳細資訊。
現在提示是不能繫結800埠,那是因為SELinux把httpd的埠固定了幾個預設的埠
[root@localhost Server]# semanage port -l | grep http
http_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010
http_cache_port_t udp 3130, 11211
http_port_t tcp 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
可以看到關於http的所有埠使用情況,但是800並沒有在預設使用行列中,所以系統不能繫結這個埠,也就啟動不了服務。
但是我們可以通過semanage命令來把這個埠新增到http可以使用的行列中
[root@localhost ~]# semanage port -a -t http_port-t _p tcp 800
再檢視一次埠使用行列
[root@localhost ~]# semanage port -l | grep http
http_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010
http_cache_port_t udp 3130, 11211
http_port_t tcp 800, 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
現在800埠已經可以被http服務使用了,我們可以正常啟動http服務了
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
服務正常啟動!!!!!!!
相關文章
- SELinux簡介和解決方法Linux
- Webapck 簡單配置Web
- VS code 簡單配置
- logback的簡單配置
- spingMVC框架簡單配置MVC框架
- SELinux: 如何讓selinux對某些命令放行,自定義selinux規則。Linux
- Web Scraper簡單配置方法Web
- webpack(簡單安裝配置)Web
- 一個簡單多庫配置
- 交換機的簡單配置
- node webpack4.6簡單配置Web
- switch_selinux.sh | 開啟或禁用SELinuxLinux
- 一個簡單vue.config.js配置和axios簡單封裝VueJSiOS封裝
- 伺服器簡單郵箱配置伺服器
- Elasticsearch 的安裝和簡單配置Elasticsearch
- Django安裝與簡單配置(1)Django
- CentOS 7 以上防火牆簡單配置CentOS防火牆
- Spring Cloud Gateway + Nacos(1)簡單配置SpringCloudGateway
- 配置中心之Nacos簡介,使用及Go簡單整合Go
- Mybatis【配置檔案】就是這麼簡單MyBatis
- 把玩Alpine linux(三):簡單手動配置Linux
- webpack4簡單實用配置解析Web
- 簡單說說webpack的配置檔案Web
- log4j簡單配置解釋
- Ubuntu-kali配置動態ip(簡單)Ubuntu
- 01 . SaltStack部署配置及簡單應用
- SELinux如何永久禁用Linux
- SELinux 安全模型——TELinux模型
- 什麼是seLinux?Linux關閉seLinux有什麼影響?Linux
- Linux中selinux是什麼意思?SELinux的主要作用有哪些?Linux
- Gulp4 Koa專案簡單配置示例
- PostgreSQLlibpqmulti-host配置與簡單HA實現SQL
- TS3AudioBot的簡單安裝配置S3
- jenkins簡單安裝及配置(Windows環境JenkinsWindows
- CentOS 8 禁用 SELinux 教程CentOSLinux
- Android SELinux許可權AndroidLinux
- Laravel5.7+vue+element-ui 配置及簡單使用LaravelVueUI
- Mysql Master-slave複製簡單配置記錄MySqlAST
- SpringBoot獲取配置檔案,就這麼簡單。Spring Boot