Ⅱ 10.selinux的初級管理
1.什麼時selinux
selinux,內核級加強型防火牆
2.如何管理selinux級別
selinux開啓或者關閉)
vim /etc/sysconfig/selinux
selinux=enforcing ##強制狀態
selinux=permissive ##警告狀態
selinux=disabled ##關閉狀態
getenforce ##查看狀態
當selinux開啓時
setenforce 0|1 ##更改selinux運行級別
-0 表示 permissive #警告
-1 表示 enforcing #強制
3.如何更改文件安全上下文
臨時更改)
chcon -t 安全上下文 文件
chcon -t public_content_t /westos-R
永久更改)
semanage fcontext -l ##列出內核安全上下文列表內容
semanage fcontext -a -t public_content_t '/westos(/.*)?'
restorecon -FvvR /westos/
示例:
[root@localhost ~]# mkdir /westos
[root@localhost ~]# ps auxZ | grep vsftpd
[root@localhost ~]# ls -lZ /var/ftp/
[root@localhost ~]# ls -Zd /westos/
[root@localhost ~]# semanage fcontext -l | grep westos
[root@localhost ~]# semanage fcontext -l | grep /var/ftp
[root@localhost ~]# semanage fcontext -a -t public_content_t '/westos(/.*)?'
[root@localhost ~]# semanage fcontext -l | grep westos
[root@localhost ~]# ls -Zd /westos/
[root@localhost ~]# restorecon -RvvF /westos/
[root@localhost ~]# ls -Zd /westos/
[root@localhost ~]# touch /westos/file
[root@localhost ~]# ls -Z /westos/
4.如何控制selinux對服務功能的開關
getsebool -a| grep 服務名稱 #顯示布爾值
getsebool -a | grep ftp
setsebool -P 功能bool值 on|off #修改 SELinux 策略 , 以永久保留修改。
setsebool -Pftpd_anon_dir on
5.監控selinux的錯誤信息
安裝 setroubleshoot-server 軟件包
[root@localhost ~]# yum info setroubleshoot-server.x86_64 #查看已安裝及可安裝的軟件包
[root@localhost ~]# yum install setroubleshoot-server.x86_64 -y#安裝seltroubleshoo-server服務
etroubleshoot-server 偵聽 /var/log/audit/audit.log 中的審覈信息並將簡短摘要發送至 /var/log/messages
摘要包括 SELinux 衝突的唯一標識符 ( UUIDs ),可用於收集更多信息。 Sealert -l UUID 用於生成特定事件的報告。 Sealert -a
/var/log/audit/audit.log 用於在該文件中生成所有事件的報告