配置
SELinux
相關命令:
getenforce: 獲取selinux當前狀態 sestatus :查看selinux狀態 setenforce 0|1 1: 設置為enforcing
配置文件:
/boot/grub/grub.conf 使用
selinux=0禁用SELinux
/etc/sysconfig/selinux /etc/selinux/config SELINUX={disabled|enforcing|permissive}
修改
SELinux安全標簽
給文件重新打安全標簽:
chcon [OPTION]... [-u USER] [-r ROLE] [-t
TYPE] FILE…
chcon [OPTION]... --reference=RFILE FILE... -R:遞歸打標;
恢復目錄或文件默認的安全上下文:
restorecon [-R] /path/to/somewhere
默認安全上下文查詢與修改
semanage 來自 policycoreutils-python包
查看默認的安全上下文
semanage fcontext –l
添加安全上下文 semanage fcontext -a –t httpd_sys_content_t
‘/testdir(/.*)?’
restorecon –Rv /testdir
刪除安全上下文
semanage fcontext -d –t httpd_sys_content_t
‘/testdir(/.*)?’
Selinux端口標簽
查看端口標簽
semanage port –l
添加端口
semanage port -a -t port_label -p tcp|udp PORT
semanage port -a -t http_port_t -p tcp 9527 v
刪除端口
semanage port -d -t port_label -p tcp|udp PORT
semanage port -d -t http_port_t -p tcp 9527
修改
semanage port -m -t port_label -p tcp|udp PORT
semanage port -m -t http_port_t -p tcp 9527
SELinux布爾值
布爾型規則:
getsebool setsebool
查看bool命令:
getsebool [-a] semanage boolean –l semanage boolean -l –C 查看修改過的布爾值
設置bool值命令:
setsebool [-P] boolean value setsebool [-P] Boolean=value
SELinux 日志管理
yum install setroubleshoot* (重啟生效)
將錯誤的信息寫入
/var/log/message
grep setroubleshoot /var/log/messages
sealert -l UUID
查看安全事件日志說明
sealert -a /var/log/audit/audit.log
掃描并分析日志
SELinux幫助
yum -y install selinux-policy-devel 7
yum -y install selinux-policy-doc 6
mandb 7
Makewhatis 6
-
httpd服務,改變網站的默認主目錄為/website,添加SELinux文件標簽規則,設置http_sys_content_t到 /website及目錄下所有文件,使網站可訪問
yum -y install httpd | policycoreutils-python | setroubleshoot | selinux - policy -devel /doc
在用戶家目錄新建/website即可。
更改
etc/httpd/conf/httpd.conf
將userdir disabled 禁用
將userdir 后跟的文件夾改為用戶家目錄的/website文件夾即可
為文件打上標簽。
chcon -t –t httpd_sys_content_t ' /website(/.*)?' semanage fcontext -a –t httpd_sys_content_t ' /website(/.*)?'
-
修改網站端口為9527,增加SELinux端口標簽,使網站可訪問
semanage port -m -t http_port_t -p tcp 9527
-
啟用SELinux布爾值,使用戶student的家目錄可通過 http訪問
setseboo boolean 1
原創文章,作者:sjfbjs,如若轉載,請注明出處:http://www.www58058.com/46617
對命令的使用介紹的很全面,但是內容再充實點就好了。